/* Generated by Cython 0.25.1 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "_emirge_C.h", 
            "pykseq/kseq.h"
        ], 
        "extra_compile_args": [
            "-O3"
        ], 
        "include_dirs": [
            "./pykseq"
        ], 
        "libraries": [
            "z"
        ]
    }, 
    "module_name": "_emirge_amplicon"
}
END: Cython Metadata */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_25_1"
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000)
    #define HAVE_LONG_LONG
  #endif
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef METH_FASTCALL
  #define METH_FASTCALL 0x80
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args,
                                              Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)

#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

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


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

#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

#define __PYX_HAVE___emirge_amplicon
#define __PYX_HAVE_API___emirge_amplicon
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include "zlib.h"
#include "kseq.h"
#include "_emirge_C.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

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


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

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

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


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


/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":725
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":726
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":727
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":728
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":732
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":733
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":734
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":735
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":739
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":740
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":749
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":750
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":751
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":753
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":754
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":755
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":757
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":758
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":760
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":761
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":762
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif
static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

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


/*--- Type declarations ---*/
struct __pyx_obj_6pykseq_Kseq;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":764
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":765
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":766
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":768
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;

/* "pykseq.pxd":6
 * from zlib cimport gzFile, gzopen, gzclose, gzrewind
 * 
 * ctypedef kseq.kseq_t *kseq_t_pointer             # <<<<<<<<<<<<<<
 * 
 * cdef class Kseq:
 */
typedef kseq_t *__pyx_t_6pykseq_kseq_t_pointer;

/* "pykseq.pxd":8
 * ctypedef kseq.kseq_t *kseq_t_pointer
 * 
 * cdef class Kseq:             # <<<<<<<<<<<<<<
 *     cdef gzFile *_c_file
 *     cdef int l
 */
struct __pyx_obj_6pykseq_Kseq {
  PyObject_HEAD
  struct __pyx_vtabstruct_6pykseq_Kseq *__pyx_vtab;
  gzFile *_c_file;
  int l;
  kseq_t *seq;
};



struct __pyx_vtabstruct_6pykseq_Kseq {
  kseq_t *(*c_read_sequence)(struct __pyx_obj_6pykseq_Kseq *);
  PyObject *(*rewind)(struct __pyx_obj_6pykseq_Kseq *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_6pykseq_Kseq *__pyx_vtabptr_6pykseq_Kseq;

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

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

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

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

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

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif

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

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

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

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#endif

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

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

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

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

/* BufferFormatCheck.proto */
static CYTHON_INLINE int  __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type); // PROTO

/* None.proto */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t);

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

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

#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0)
#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1)
#define __Pyx_BufPtrStrided3d(type, buf, i0, s0, i1, s1, i2, s2) (type)((char*)buf + i0 * s0 + i1 * s1 + i2 * s2)
/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

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

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

/* PyFloatBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_SubtractCObj(PyObject *op1, PyObject *op2, double floatval, int inplace);
#else
#define __Pyx_PyFloat_SubtractCObj(op1, op2, floatval, inplace)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* PyFloatBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_DivideObjC(PyObject *op1, PyObject *op2, double floatval, int inplace);
#else
#define __Pyx_PyFloat_DivideObjC(op1, op2, floatval, inplace)\
    ((inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2)))
    #endif

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

/* append.proto */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#else
    #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif

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

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

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

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

/* GetVTable.proto */
static void* __Pyx_GetVtable(PyObject *dict);

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

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

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

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

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

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


/* None.proto */
static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0};
static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1};

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

/* Print.proto */
static int __Pyx_Print(PyObject*, PyObject *, int);
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value);

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int32(npy_int32 value);

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

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

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

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

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

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

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

/* PrintOne.proto */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o);

/* CIntFromPy.proto */
static CYTHON_INLINE npy_uint32 __Pyx_PyInt_As_npy_uint32(PyObject *);

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

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

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

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

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

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


/* Module declarations from 'cython' */

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

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

/* Module declarations from '__builtin__' */

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

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

/* Module declarations from 'cpython' */

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

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

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

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

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

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

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

/* Module declarations from 'zlib' */

/* Module declarations from 'kseq' */

/* Module declarations from 'pykseq' */
static PyTypeObject *__pyx_ptype_6pykseq_Kseq = 0;

/* Module declarations from '_emirge_amplicon' */
static CYTHON_INLINE int __pyx_f_16_emirge_amplicon_base_alpha2int(char); /*proto*/
static CYTHON_INLINE unsigned char __pyx_f_16_emirge_amplicon_complement_numeric_base(unsigned char); /*proto*/
static PyArrayObject *__pyx_f_16_emirge_amplicon_seq_alpha2int(char *, int); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t = { "uint32_t", NULL, sizeof(__pyx_t_5numpy_uint32_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint32_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint32_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t = { "uint8_t", NULL, sizeof(__pyx_t_5numpy_uint8_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint8_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint8_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint_t = { "uint_t", NULL, sizeof(__pyx_t_5numpy_uint_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float_t = { "float_t", NULL, sizeof(__pyx_t_5numpy_float_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int32_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int32_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t = { "uint16_t", NULL, sizeof(__pyx_t_5numpy_uint16_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint16_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint16_t), 0 };
#define __Pyx_MODULE_NAME "_emirge_amplicon"
int __pyx_module_is_main__emirge_amplicon = 0;

/* Implementation of '_emirge_amplicon' */
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_ImportError;
static const char __pyx_k_D[] = "D";
static const char __pyx_k_I[] = "I";
static const char __pyx_k_M[] = "M";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_j[] = "j";
static const char __pyx_k_l[] = "l";
static const char __pyx_k_p[] = "p";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_s[] = "s";
static const char __pyx_k_em[] = "em";
static const char __pyx_k_hi[] = "hi";
static const char __pyx_k_ii[] = "ii";
static const char __pyx_k_ks[] = "ks";
static const char __pyx_k_lo[] = "lo";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_rb[] = "rb";
static const char __pyx_k_t0[] = "t0";
static const char __pyx_k_td[] = "td";
static const char __pyx_k_bam[] = "bam";
static const char __pyx_k_chr[] = "chr";
static const char __pyx_k_col[] = "col";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_low[] = "low";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_mid[] = "mid";
static const char __pyx_k_pos[] = "pos";
static const char __pyx_k_row[] = "row";
static const char __pyx_k_sam[] = "sam";
static const char __pyx_k_seq[] = "seq";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_tid[] = "tid";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_data[] = "data";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_ks_p[] = "ks_p";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_rlen[] = "rlen";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_time[] = "time";
static const char __pyx_k_uint[] = "uint";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_count[] = "count";
static const char __pyx_k_ctime[] = "ctime";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_fetch[] = "fetch";
static const char __pyx_k_float[] = "float";
static const char __pyx_k_hit_i[] = "hit_i";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_probN[] = "probN";
static const char __pyx_k_pysam[] = "pysam";
static const char __pyx_k_qname[] = "qname";
static const char __pyx_k_quals[] = "quals";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_reads[] = "reads";
static const char __pyx_k_scipy[] = "scipy";
static const char __pyx_k_seq_i[] = "seq_i";
static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_tocoo[] = "tocoo";
static const char __pyx_k_tocsr[] = "tocsr";
static const char __pyx_k_uint8[] = "uint8";
static const char __pyx_k_zeros[] = "zeros";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_bisect[] = "bisect";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_indptr[] = "indptr";
static const char __pyx_k_midval[] = "midval";
static const char __pyx_k_pair_i[] = "pair_i";
static const char __pyx_k_priors[] = "priors";
static const char __pyx_k_py_seq[] = "py_seq";
static const char __pyx_k_read_i[] = "read_i";
static const char __pyx_k_result[] = "result";
static const char __pyx_k_sparse[] = "sparse";
static const char __pyx_k_stderr[] = "stderr";
static const char __pyx_k_uint32[] = "uint32";
static const char __pyx_k_weight[] = "weight";
static const char __pyx_k_Samfile[] = "Samfile";
static const char __pyx_k_VERBOSE[] = "_VERBOSE";
static const char __pyx_k_bamfile[] = "bamfile";
static const char __pyx_k_count_a[] = "count_a";
static const char __pyx_k_hit_seq[] = "hit_seq";
static const char __pyx_k_indices[] = "indices";
static const char __pyx_k_lengths[] = "lengths";
static const char __pyx_k_lik_col[] = "lik_col";
static const char __pyx_k_lik_coo[] = "lik_coo";
static const char __pyx_k_lik_row[] = "lik_row";
static const char __pyx_k_loop_t0[] = "loop_t0";
static const char __pyx_k_matches[] = "matches";
static const char __pyx_k_n_reads[] = "n_reads";
static const char __pyx_k_p_div_3[] = "p_div_3";
static const char __pyx_k_product[] = "product";
static const char __pyx_k_query_i[] = "query_i";
static const char __pyx_k_refname[] = "refname";
static const char __pyx_k_seconds[] = "seconds";
static const char __pyx_k_t_check[] = "t_check";
static const char __pyx_k_aln_code[] = "aln_code";
static const char __pyx_k_base_sum[] = "base_sum";
static const char __pyx_k_coverage[] = "coverage";
static const char __pyx_k_datetime[] = "datetime";
static const char __pyx_k_endswith[] = "endswith";
static const char __pyx_k_is_read2[] = "is_read2";
static const char __pyx_k_lik_data[] = "lik_data";
static const char __pyx_k_result_i[] = "result_i";
static const char __pyx_k_cullcount[] = "cullcount";
static const char __pyx_k_dead_seqs[] = "dead_seqs";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_fastafile[] = "fastafile";
static const char __pyx_k_new_seq_i[] = "new_seq_i";
static const char __pyx_k_query_seq[] = "query_seq";
static const char __pyx_k_seq_bases[] = "seq_bases";
static const char __pyx_k_tid2seq_i[] = "tid2seq_i";
static const char __pyx_k_timedelta[] = "timedelta";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_calc_probN[] = "_calc_probN";
static const char __pyx_k_convert_t0[] = "convert_t0";
static const char __pyx_k_coo_matrix[] = "coo_matrix";
static const char __pyx_k_cov_thresh[] = "cov_thresh";
static const char __pyx_k_empty_like[] = "empty_like";
static const char __pyx_k_is_reverse[] = "is_reverse";
static const char __pyx_k_max_length[] = "max_length";
static const char __pyx_k_posteriors[] = "posteriors";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_qname_temp[] = "qname_temp";
static const char __pyx_k_read_index[] = "read_index";
static const char __pyx_k_readlength[] = "readlength";
static const char __pyx_k_reads_seen[] = "reads_seen";
static const char __pyx_k_references[] = "references";
static const char __pyx_k_tid_mapped[] = "tid_mapped";
static const char __pyx_k_zeros_like[] = "zeros_like";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_alignedread[] = "alignedread";
static const char __pyx_k_aln_columns[] = "aln_columns";
static const char __pyx_k_bisect_left[] = "bisect_left";
static const char __pyx_k_denominator[] = "denominator";
static const char __pyx_k_iteration_i[] = "iteration_i";
static const char __pyx_k_likelihoods[] = "likelihoods";
static const char __pyx_k_one_minus_p[] = "one_minus_p";
static const char __pyx_k_readlengths[] = "readlengths";
static const char __pyx_k_reset_probN[] = "reset_probN";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_alncode_list[] = "alncode_list";
static const char __pyx_k_ascii_offset[] = "ascii_offset";
static const char __pyx_k_bamfile_data[] = "bamfile_data";
static const char __pyx_k_lik_row_seqi[] = "lik_row_seqi";
static const char __pyx_k_n_alignments[] = "n_alignments";
static const char __pyx_k_paired_reads[] = "paired_reads";
static const char __pyx_k_probN_single[] = "probN_single";
static const char __pyx_k_reads_mapped[] = "reads_mapped";
static const char __pyx_k_sort_indices[] = "sort_indices";
static const char __pyx_k_DEFAULT_ERROR[] = "DEFAULT_ERROR";
static const char __pyx_k_alignedread_i[] = "alignedread_i";
static const char __pyx_k_base_coverage[] = "base_coverage";
static const char __pyx_k_length_thresh[] = "length_thresh";
static const char __pyx_k_lik_col_readi[] = "lik_col_readi";
static const char __pyx_k_n_reads_total[] = "n_reads_total";
static const char __pyx_k_base_coverages[] = "base_coverages";
static const char __pyx_k_n_reads_mapped[] = "n_reads_mapped";
static const char __pyx_k_pair_collected[] = "pair_collected";
static const char __pyx_k_reads_filepath[] = "reads_filepath";
static const char __pyx_k_readtype_index[] = "readtype_index";
static const char __pyx_k_reference_base[] = "reference_base";
static const char __pyx_k_unmapped_bases[] = "unmapped_bases";
static const char __pyx_k_calc_likelihood[] = "_calc_likelihood";
static const char __pyx_k_calc_posteriors[] = "_calc_posteriors";
static const char __pyx_k_count_cigar_aln[] = "count_cigar_aln";
static const char __pyx_k_emirge_amplicon[] = "_emirge_amplicon";
static const char __pyx_k_posteriors_data[] = "posteriors_data";
static const char __pyx_k_process_bamfile[] = "process_bamfile";
static const char __pyx_k_read_i_to_cache[] = "read_i_to_cache";
static const char __pyx_k_reads1_filepath[] = "reads1_filepath";
static const char __pyx_k_reads2_filepath[] = "reads2_filepath";
static const char __pyx_k_samfile_lengths[] = "samfile_lengths";
static const char __pyx_k_references_array[] = "references_array";
static const char __pyx_k_base_coverages_2d[] = "base_coverages_2d";
static const char __pyx_k_initial_iteration[] = "initial_iteration";
static const char __pyx_k_posteriors_indptr[] = "posteriors_indptr";
static const char __pyx_k_hit_unmapped_bases[] = "hit_unmapped_bases";
static const char __pyx_k_posteriors_indices[] = "posteriors_indices";
static const char __pyx_k_reads_ascii_offset[] = "reads_ascii_offset";
static const char __pyx_k_references_lengths[] = "references_lengths";
static const char __pyx_k_samfile_references[] = "samfile_references";
static const char __pyx_k_min_length_coverage[] = "min_length_coverage";
static const char __pyx_k_current_bam_filename[] = "current_bam_filename";
static const char __pyx_k_query_unmapped_bases[] = "query_unmapped_bases";
static const char __pyx_k_populate_reads_arrays[] = "populate_reads_arrays";
static const char __pyx_k_reads_seen_this_round[] = "reads_seen_this_round";
static const char __pyx_k_percent_length_covered[] = "percent_length_covered";
static const char __pyx_k_min_length_coverage_def[] = "min_length_coverage_def";
static const char __pyx_k_sequence_i2sequence_name[] = "sequence_i2sequence_name";
static const char __pyx_k_sequence_name2sequence_i[] = "sequence_name2sequence_i";
static const char __pyx_k_unknown_alignment_code_s[] = "unknown alignment code: '%s'";
static const char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static const char __pyx_k_emirge_amplicon_pyx_contains_h[] = "\n_emirge_amplicon.pyx contains helper cython functions for emirge_amplicon.py\n\nEMIRGE: Expectation-Maximization Iterative Reconstruction of Genes from the Environment\nCopyright (C) 2010-2016 Christopher S. Miller  (christopher.s.miller@ucdenver.edu)\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>\n\nhttps://github.com/csmiller/EMIRGE\n";
static const char __pyx_k_sequence_i2sequence_name_array[] = "sequence_i2sequence_name_array";
static const char __pyx_k_Culled_s_sequences_in_iteration[] = "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads";
static const char __pyx_k_home_travis_build_csmiller_EMIR[] = "/home/travis/build/csmiller/EMIRGE/_emirge_amplicon.pyx";
static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import";
static const char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static const char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static const char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported";
static const char __pyx_k_WARNING_invalid_base_in_base_alp[] = "WARNING: invalid base in base_alpha2int: %s";
static const char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous";
static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import";
static const char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short.";
static PyObject *__pyx_kp_s_Culled_s_sequences_in_iteration;
static PyObject *__pyx_n_s_D;
static PyObject *__pyx_n_s_DEFAULT_ERROR;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2;
static PyObject *__pyx_n_s_I;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_n_s_M;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_s_Samfile;
static PyObject *__pyx_n_s_VERBOSE;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_WARNING_invalid_base_in_base_alp;
static PyObject *__pyx_n_s_alignedread;
static PyObject *__pyx_n_s_alignedread_i;
static PyObject *__pyx_n_s_aln_code;
static PyObject *__pyx_n_s_aln_columns;
static PyObject *__pyx_n_s_alncode_list;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_ascii_offset;
static PyObject *__pyx_n_s_bam;
static PyObject *__pyx_n_s_bamfile;
static PyObject *__pyx_n_s_bamfile_data;
static PyObject *__pyx_n_s_base_coverage;
static PyObject *__pyx_n_s_base_coverages;
static PyObject *__pyx_n_s_base_coverages_2d;
static PyObject *__pyx_n_s_base_sum;
static PyObject *__pyx_n_s_bisect;
static PyObject *__pyx_n_s_bisect_left;
static PyObject *__pyx_n_s_calc_likelihood;
static PyObject *__pyx_n_s_calc_posteriors;
static PyObject *__pyx_n_s_calc_probN;
static PyObject *__pyx_n_s_chr;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_col;
static PyObject *__pyx_n_s_convert_t0;
static PyObject *__pyx_n_s_coo_matrix;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_count;
static PyObject *__pyx_n_s_count_a;
static PyObject *__pyx_n_s_count_cigar_aln;
static PyObject *__pyx_n_s_cov_thresh;
static PyObject *__pyx_n_s_coverage;
static PyObject *__pyx_n_s_ctime;
static PyObject *__pyx_n_s_cullcount;
static PyObject *__pyx_n_s_current_bam_filename;
static PyObject *__pyx_n_s_data;
static PyObject *__pyx_n_s_datetime;
static PyObject *__pyx_n_s_dead_seqs;
static PyObject *__pyx_n_s_denominator;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_em;
static PyObject *__pyx_n_s_emirge_amplicon;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_empty_like;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_endswith;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_fastafile;
static PyObject *__pyx_n_s_fetch;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_float;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_hi;
static PyObject *__pyx_n_s_hit_i;
static PyObject *__pyx_n_s_hit_seq;
static PyObject *__pyx_n_s_hit_unmapped_bases;
static PyObject *__pyx_kp_s_home_travis_build_csmiller_EMIR;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_ii;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_n_s_indptr;
static PyObject *__pyx_n_s_initial_iteration;
static PyObject *__pyx_n_s_is_read2;
static PyObject *__pyx_n_s_is_reverse;
static PyObject *__pyx_n_s_iteration_i;
static PyObject *__pyx_n_s_j;
static PyObject *__pyx_n_s_ks;
static PyObject *__pyx_n_s_ks_p;
static PyObject *__pyx_n_s_l;
static PyObject *__pyx_n_s_length_thresh;
static PyObject *__pyx_n_s_lengths;
static PyObject *__pyx_n_s_lik_col;
static PyObject *__pyx_n_s_lik_col_readi;
static PyObject *__pyx_n_s_lik_coo;
static PyObject *__pyx_n_s_lik_data;
static PyObject *__pyx_n_s_lik_row;
static PyObject *__pyx_n_s_lik_row_seqi;
static PyObject *__pyx_n_s_likelihoods;
static PyObject *__pyx_n_s_lo;
static PyObject *__pyx_n_s_loop_t0;
static PyObject *__pyx_n_s_low;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_matches;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_length;
static PyObject *__pyx_n_s_mid;
static PyObject *__pyx_n_s_midval;
static PyObject *__pyx_n_s_min_length_coverage;
static PyObject *__pyx_n_s_min_length_coverage_def;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_n_alignments;
static PyObject *__pyx_n_s_n_reads;
static PyObject *__pyx_n_s_n_reads_mapped;
static PyObject *__pyx_n_s_n_reads_total;
static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous;
static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou;
static PyObject *__pyx_n_s_new_seq_i;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_kp_s_numpy_core_multiarray_failed_to;
static PyObject *__pyx_kp_s_numpy_core_umath_failed_to_impor;
static PyObject *__pyx_n_s_one_minus_p;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_p;
static PyObject *__pyx_n_s_p_div_3;
static PyObject *__pyx_n_s_pair_collected;
static PyObject *__pyx_n_s_pair_i;
static PyObject *__pyx_n_s_paired_reads;
static PyObject *__pyx_n_s_percent_length_covered;
static PyObject *__pyx_n_s_populate_reads_arrays;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_posteriors;
static PyObject *__pyx_n_s_posteriors_data;
static PyObject *__pyx_n_s_posteriors_indices;
static PyObject *__pyx_n_s_posteriors_indptr;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_priors;
static PyObject *__pyx_n_s_probN;
static PyObject *__pyx_n_s_probN_single;
static PyObject *__pyx_n_s_process_bamfile;
static PyObject *__pyx_n_s_product;
static PyObject *__pyx_n_s_py_seq;
static PyObject *__pyx_n_s_pysam;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_qname;
static PyObject *__pyx_n_s_qname_temp;
static PyObject *__pyx_n_s_quals;
static PyObject *__pyx_n_s_query_i;
static PyObject *__pyx_n_s_query_seq;
static PyObject *__pyx_n_s_query_unmapped_bases;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rb;
static PyObject *__pyx_n_s_read_i;
static PyObject *__pyx_n_s_read_i_to_cache;
static PyObject *__pyx_n_s_read_index;
static PyObject *__pyx_n_s_readlength;
static PyObject *__pyx_n_s_readlengths;
static PyObject *__pyx_n_s_reads;
static PyObject *__pyx_n_s_reads1_filepath;
static PyObject *__pyx_n_s_reads2_filepath;
static PyObject *__pyx_n_s_reads_ascii_offset;
static PyObject *__pyx_n_s_reads_filepath;
static PyObject *__pyx_n_s_reads_mapped;
static PyObject *__pyx_n_s_reads_seen;
static PyObject *__pyx_n_s_reads_seen_this_round;
static PyObject *__pyx_n_s_readtype_index;
static PyObject *__pyx_n_s_reference_base;
static PyObject *__pyx_n_s_references;
static PyObject *__pyx_n_s_references_array;
static PyObject *__pyx_n_s_references_lengths;
static PyObject *__pyx_n_s_refname;
static PyObject *__pyx_n_s_reset_probN;
static PyObject *__pyx_n_s_result;
static PyObject *__pyx_n_s_result_i;
static PyObject *__pyx_n_s_rlen;
static PyObject *__pyx_n_s_row;
static PyObject *__pyx_n_s_s;
static PyObject *__pyx_n_s_sam;
static PyObject *__pyx_n_s_samfile_lengths;
static PyObject *__pyx_n_s_samfile_references;
static PyObject *__pyx_n_s_scipy;
static PyObject *__pyx_n_s_seconds;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_seq_bases;
static PyObject *__pyx_n_s_seq_i;
static PyObject *__pyx_n_s_sequence_i2sequence_name;
static PyObject *__pyx_n_s_sequence_i2sequence_name_array;
static PyObject *__pyx_n_s_sequence_name2sequence_i;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_sort_indices;
static PyObject *__pyx_n_s_sparse;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_stderr;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_t0;
static PyObject *__pyx_n_s_t_check;
static PyObject *__pyx_n_s_td;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_tid;
static PyObject *__pyx_n_s_tid2seq_i;
static PyObject *__pyx_n_s_tid_mapped;
static PyObject *__pyx_n_s_time;
static PyObject *__pyx_n_s_timedelta;
static PyObject *__pyx_n_s_tocoo;
static PyObject *__pyx_n_s_tocsr;
static PyObject *__pyx_n_s_uint;
static PyObject *__pyx_n_s_uint32;
static PyObject *__pyx_n_s_uint8;
static PyObject *__pyx_kp_s_unknown_alignment_code_s;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_unmapped_bases;
static PyObject *__pyx_n_s_weight;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_n_s_zeros_like;
static PyObject *__pyx_pf_16_emirge_amplicon__calc_likelihood(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_2_calc_probN(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_4_calc_posteriors(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_6count_cigar_aln(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_query_seq, char *__pyx_v_hit_seq, PyArrayObject *__pyx_v_query_unmapped_bases, PyArrayObject *__pyx_v_hit_unmapped_bases, unsigned int __pyx_v_query_i, unsigned int __pyx_v_hit_i, PyObject *__pyx_v_alncode_list); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_8populate_reads_arrays(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_10process_bamfile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em, CYTHON_UNUSED int __pyx_v_ascii_offset); /* proto */
static PyObject *__pyx_pf_16_emirge_amplicon_12reset_probN(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_float_1_0;
static PyObject *__pyx_float_3_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_6;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_codeobj__15;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__23;
static PyObject *__pyx_codeobj__25;
static PyObject *__pyx_codeobj__27;

/* "_emirge_amplicon.pyx":47
 *     static_const_double_ptr qual2p_div_3
 * 
 * cdef inline int base_alpha2int(char base_ascii):             # <<<<<<<<<<<<<<
 *     """
 *     base2i = {"A":0,"T":1,"C":2,"G":3}
 */

static CYTHON_INLINE int __pyx_f_16_emirge_amplicon_base_alpha2int(char __pyx_v_base_ascii) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("base_alpha2int", 0);

  /* "_emirge_amplicon.pyx":51
 *     base2i = {"A":0,"T":1,"C":2,"G":3}
 *     """
 *     if base_ascii == 65:   # <int>('A'):             # <<<<<<<<<<<<<<
 *         return 0
 *     elif base_ascii == 84: # <int>('T'):
 */
  switch (__pyx_v_base_ascii) {
    case 65:

    /* "_emirge_amplicon.pyx":52
 *     """
 *     if base_ascii == 65:   # <int>('A'):
 *         return 0             # <<<<<<<<<<<<<<
 *     elif base_ascii == 84: # <int>('T'):
 *         return 1
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":51
 *     base2i = {"A":0,"T":1,"C":2,"G":3}
 *     """
 *     if base_ascii == 65:   # <int>('A'):             # <<<<<<<<<<<<<<
 *         return 0
 *     elif base_ascii == 84: # <int>('T'):
 */
    break;

    /* "_emirge_amplicon.pyx":53
 *     if base_ascii == 65:   # <int>('A'):
 *         return 0
 *     elif base_ascii == 84: # <int>('T'):             # <<<<<<<<<<<<<<
 *         return 1
 *     elif base_ascii == 67:  # <int>('C'):
 */
    case 84:

    /* "_emirge_amplicon.pyx":54
 *         return 0
 *     elif base_ascii == 84: # <int>('T'):
 *         return 1             # <<<<<<<<<<<<<<
 *     elif base_ascii == 67:  # <int>('C'):
 *         return 2
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":53
 *     if base_ascii == 65:   # <int>('A'):
 *         return 0
 *     elif base_ascii == 84: # <int>('T'):             # <<<<<<<<<<<<<<
 *         return 1
 *     elif base_ascii == 67:  # <int>('C'):
 */
    break;

    /* "_emirge_amplicon.pyx":55
 *     elif base_ascii == 84: # <int>('T'):
 *         return 1
 *     elif base_ascii == 67:  # <int>('C'):             # <<<<<<<<<<<<<<
 *         return 2
 *     elif base_ascii == 71:  # <int>('G'):
 */
    case 67:

    /* "_emirge_amplicon.pyx":56
 *         return 1
 *     elif base_ascii == 67:  # <int>('C'):
 *         return 2             # <<<<<<<<<<<<<<
 *     elif base_ascii == 71:  # <int>('G'):
 *         return 3
 */
    __pyx_r = 2;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":55
 *     elif base_ascii == 84: # <int>('T'):
 *         return 1
 *     elif base_ascii == 67:  # <int>('C'):             # <<<<<<<<<<<<<<
 *         return 2
 *     elif base_ascii == 71:  # <int>('G'):
 */
    break;

    /* "_emirge_amplicon.pyx":57
 *     elif base_ascii == 67:  # <int>('C'):
 *         return 2
 *     elif base_ascii == 71:  # <int>('G'):             # <<<<<<<<<<<<<<
 *         return 3
 *     elif base_ascii == 78:  # <int>('N'):
 */
    case 71:

    /* "_emirge_amplicon.pyx":58
 *         return 2
 *     elif base_ascii == 71:  # <int>('G'):
 *         return 3             # <<<<<<<<<<<<<<
 *     elif base_ascii == 78:  # <int>('N'):
 *         return 4
 */
    __pyx_r = 3;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":57
 *     elif base_ascii == 67:  # <int>('C'):
 *         return 2
 *     elif base_ascii == 71:  # <int>('G'):             # <<<<<<<<<<<<<<
 *         return 3
 *     elif base_ascii == 78:  # <int>('N'):
 */
    break;

    /* "_emirge_amplicon.pyx":59
 *     elif base_ascii == 71:  # <int>('G'):
 *         return 3
 *     elif base_ascii == 78:  # <int>('N'):             # <<<<<<<<<<<<<<
 *         return 4
 *     else:
 */
    case 78:

    /* "_emirge_amplicon.pyx":60
 *         return 3
 *     elif base_ascii == 78:  # <int>('N'):
 *         return 4             # <<<<<<<<<<<<<<
 *     else:
 *         print >> sys.stderr, "WARNING: invalid base in base_alpha2int: %s"%chr(base_ascii)
 */
    __pyx_r = 4;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":59
 *     elif base_ascii == 71:  # <int>('G'):
 *         return 3
 *     elif base_ascii == 78:  # <int>('N'):             # <<<<<<<<<<<<<<
 *         return 4
 *     else:
 */
    break;
    default:

    /* "_emirge_amplicon.pyx":62
 *         return 4
 *     else:
 *         print >> sys.stderr, "WARNING: invalid base in base_alpha2int: %s"%chr(base_ascii)             # <<<<<<<<<<<<<<
 *         return 4
 * 
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_stderr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_From_char(__pyx_v_base_ascii); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_WARNING_invalid_base_in_base_alp, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__Pyx_PrintOne(__pyx_t_2, __pyx_t_3) < 0) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "_emirge_amplicon.pyx":63
 *     else:
 *         print >> sys.stderr, "WARNING: invalid base in base_alpha2int: %s"%chr(base_ascii)
 *         return 4             # <<<<<<<<<<<<<<
 * 
 * cdef inline unsigned char complement_numeric_base(unsigned char c):
 */
    __pyx_r = 4;
    goto __pyx_L0;
    break;
  }

  /* "_emirge_amplicon.pyx":47
 *     static_const_double_ptr qual2p_div_3
 * 
 * cdef inline int base_alpha2int(char base_ascii):             # <<<<<<<<<<<<<<
 *     """
 *     base2i = {"A":0,"T":1,"C":2,"G":3}
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("_emirge_amplicon.base_alpha2int", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":65
 *         return 4
 * 
 * cdef inline unsigned char complement_numeric_base(unsigned char c):             # <<<<<<<<<<<<<<
 *         if c == 0:
 *             return 1
 */

static CYTHON_INLINE unsigned char __pyx_f_16_emirge_amplicon_complement_numeric_base(unsigned char __pyx_v_c) {
  unsigned char __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("complement_numeric_base", 0);

  /* "_emirge_amplicon.pyx":66
 * 
 * cdef inline unsigned char complement_numeric_base(unsigned char c):
 *         if c == 0:             # <<<<<<<<<<<<<<
 *             return 1
 *         elif c == 1:
 */
  switch (__pyx_v_c) {
    case 0:

    /* "_emirge_amplicon.pyx":67
 * cdef inline unsigned char complement_numeric_base(unsigned char c):
 *         if c == 0:
 *             return 1             # <<<<<<<<<<<<<<
 *         elif c == 1:
 *             return 0
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":66
 * 
 * cdef inline unsigned char complement_numeric_base(unsigned char c):
 *         if c == 0:             # <<<<<<<<<<<<<<
 *             return 1
 *         elif c == 1:
 */
    break;

    /* "_emirge_amplicon.pyx":68
 *         if c == 0:
 *             return 1
 *         elif c == 1:             # <<<<<<<<<<<<<<
 *             return 0
 *         elif c == 2:
 */
    case 1:

    /* "_emirge_amplicon.pyx":69
 *             return 1
 *         elif c == 1:
 *             return 0             # <<<<<<<<<<<<<<
 *         elif c == 2:
 *             return 3
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":68
 *         if c == 0:
 *             return 1
 *         elif c == 1:             # <<<<<<<<<<<<<<
 *             return 0
 *         elif c == 2:
 */
    break;

    /* "_emirge_amplicon.pyx":70
 *         elif c == 1:
 *             return 0
 *         elif c == 2:             # <<<<<<<<<<<<<<
 *             return 3
 *         elif c == 3:
 */
    case 2:

    /* "_emirge_amplicon.pyx":71
 *             return 0
 *         elif c == 2:
 *             return 3             # <<<<<<<<<<<<<<
 *         elif c == 3:
 *             return 2
 */
    __pyx_r = 3;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":70
 *         elif c == 1:
 *             return 0
 *         elif c == 2:             # <<<<<<<<<<<<<<
 *             return 3
 *         elif c == 3:
 */
    break;

    /* "_emirge_amplicon.pyx":72
 *         elif c == 2:
 *             return 3
 *         elif c == 3:             # <<<<<<<<<<<<<<
 *             return 2
 *         else:  # just set any non ACTG to N
 */
    case 3:

    /* "_emirge_amplicon.pyx":73
 *             return 3
 *         elif c == 3:
 *             return 2             # <<<<<<<<<<<<<<
 *         else:  # just set any non ACTG to N
 *             return 4
 */
    __pyx_r = 2;
    goto __pyx_L0;

    /* "_emirge_amplicon.pyx":72
 *         elif c == 2:
 *             return 3
 *         elif c == 3:             # <<<<<<<<<<<<<<
 *             return 2
 *         else:  # just set any non ACTG to N
 */
    break;
    default:

    /* "_emirge_amplicon.pyx":75
 *             return 2
 *         else:  # just set any non ACTG to N
 *             return 4             # <<<<<<<<<<<<<<
 * 
 * @cython.boundscheck(False)
 */
    __pyx_r = 4;
    goto __pyx_L0;
    break;
  }

  /* "_emirge_amplicon.pyx":65
 *         return 4
 * 
 * cdef inline unsigned char complement_numeric_base(unsigned char c):             # <<<<<<<<<<<<<<
 *         if c == 0:
 *             return 1
 */

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

/* "_emirge_amplicon.pyx":78
 * 
 * @cython.boundscheck(False)
 * def _calc_likelihood(em):             # <<<<<<<<<<<<<<
 *     """
 *     Cython helper function with typed data structures, fast looping.
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_1_calc_likelihood(PyObject *__pyx_self, PyObject *__pyx_v_em); /*proto*/
static char __pyx_doc_16_emirge_amplicon__calc_likelihood[] = "\n    Cython helper function with typed data structures, fast looping.\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_1_calc_likelihood = {"_calc_likelihood", (PyCFunction)__pyx_pw_16_emirge_amplicon_1_calc_likelihood, METH_O, __pyx_doc_16_emirge_amplicon__calc_likelihood};
static PyObject *__pyx_pw_16_emirge_amplicon_1_calc_likelihood(PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calc_likelihood (wrapper)", 0);
  __pyx_r = __pyx_pf_16_emirge_amplicon__calc_likelihood(__pyx_self, ((PyObject *)__pyx_v_em));

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

static PyObject *__pyx_pf_16_emirge_amplicon__calc_likelihood(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em) {
  CYTHON_UNUSED PyObject *__pyx_v_t0 = NULL;
  PyArrayObject *__pyx_v_bamfile_data = 0;
  PyArrayObject *__pyx_v_reads = 0;
  PyArrayObject *__pyx_v_quals = 0;
  PyObject *__pyx_v_probN = 0;
  int __pyx_v_paired_reads;
  Py_ssize_t __pyx_v_l;
  PyArrayObject *__pyx_v_lik_row_seqi = 0;
  PyArrayObject *__pyx_v_lik_col_readi = 0;
  PyArrayObject *__pyx_v_lik_data = 0;
  unsigned int __pyx_v_alignedread_i;
  unsigned int __pyx_v_seq_i;
  unsigned int __pyx_v_read_i;
  unsigned int __pyx_v_pair_i;
  unsigned int __pyx_v_rlen;
  unsigned int __pyx_v_pos;
  int __pyx_v_is_reverse;
  double __pyx_v_p;
  double __pyx_v_s;
  double __pyx_v_result;
  unsigned int __pyx_v_i;
  unsigned int __pyx_v_ii;
  unsigned int __pyx_v_j;
  int __pyx_v_pair_collected;
  unsigned int __pyx_v_result_i;
  PyArrayObject *__pyx_v_probN_single = 0;
  PyArrayObject *__pyx_v_dead_seqs = 0;
  PyObject *__pyx_v_loop_t0 = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_td = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bamfile_data;
  __Pyx_Buffer __pyx_pybuffer_bamfile_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_dead_seqs;
  __Pyx_Buffer __pyx_pybuffer_dead_seqs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_col_readi;
  __Pyx_Buffer __pyx_pybuffer_lik_col_readi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_data;
  __Pyx_Buffer __pyx_pybuffer_lik_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_row_seqi;
  __Pyx_Buffer __pyx_pybuffer_lik_row_seqi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_probN_single;
  __Pyx_Buffer __pyx_pybuffer_probN_single;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_quals;
  __Pyx_Buffer __pyx_pybuffer_quals;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads;
  __Pyx_Buffer __pyx_pybuffer_reads;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyArrayObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  PyArrayObject *__pyx_t_13 = NULL;
  PyArrayObject *__pyx_t_14 = NULL;
  PyArrayObject *__pyx_t_15 = NULL;
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  unsigned int __pyx_t_20;
  size_t __pyx_t_21;
  npy_intp __pyx_t_22;
  size_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  size_t __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  size_t __pyx_t_27;
  size_t __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  size_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  size_t __pyx_t_32;
  Py_ssize_t __pyx_t_33;
  size_t __pyx_t_34;
  Py_ssize_t __pyx_t_35;
  unsigned int __pyx_t_36;
  unsigned int __pyx_t_37;
  unsigned int __pyx_t_38;
  size_t __pyx_t_39;
  size_t __pyx_t_40;
  size_t __pyx_t_41;
  size_t __pyx_t_42;
  size_t __pyx_t_43;
  size_t __pyx_t_44;
  size_t __pyx_t_45;
  size_t __pyx_t_46;
  size_t __pyx_t_47;
  size_t __pyx_t_48;
  size_t __pyx_t_49;
  size_t __pyx_t_50;
  size_t __pyx_t_51;
  size_t __pyx_t_52;
  size_t __pyx_t_53;
  size_t __pyx_t_54;
  size_t __pyx_t_55;
  size_t __pyx_t_56;
  size_t __pyx_t_57;
  size_t __pyx_t_58;
  size_t __pyx_t_59;
  size_t __pyx_t_60;
  size_t __pyx_t_61;
  size_t __pyx_t_62;
  size_t __pyx_t_63;
  size_t __pyx_t_64;
  size_t __pyx_t_65;
  size_t __pyx_t_66;
  size_t __pyx_t_67;
  PyObject *__pyx_t_68 = NULL;
  __Pyx_RefNannySetupContext("_calc_likelihood", 0);
  __pyx_pybuffer_bamfile_data.pybuffer.buf = NULL;
  __pyx_pybuffer_bamfile_data.refcount = 0;
  __pyx_pybuffernd_bamfile_data.data = NULL;
  __pyx_pybuffernd_bamfile_data.rcbuffer = &__pyx_pybuffer_bamfile_data;
  __pyx_pybuffer_reads.pybuffer.buf = NULL;
  __pyx_pybuffer_reads.refcount = 0;
  __pyx_pybuffernd_reads.data = NULL;
  __pyx_pybuffernd_reads.rcbuffer = &__pyx_pybuffer_reads;
  __pyx_pybuffer_quals.pybuffer.buf = NULL;
  __pyx_pybuffer_quals.refcount = 0;
  __pyx_pybuffernd_quals.data = NULL;
  __pyx_pybuffernd_quals.rcbuffer = &__pyx_pybuffer_quals;
  __pyx_pybuffer_lik_row_seqi.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_row_seqi.refcount = 0;
  __pyx_pybuffernd_lik_row_seqi.data = NULL;
  __pyx_pybuffernd_lik_row_seqi.rcbuffer = &__pyx_pybuffer_lik_row_seqi;
  __pyx_pybuffer_lik_col_readi.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_col_readi.refcount = 0;
  __pyx_pybuffernd_lik_col_readi.data = NULL;
  __pyx_pybuffernd_lik_col_readi.rcbuffer = &__pyx_pybuffer_lik_col_readi;
  __pyx_pybuffer_lik_data.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_data.refcount = 0;
  __pyx_pybuffernd_lik_data.data = NULL;
  __pyx_pybuffernd_lik_data.rcbuffer = &__pyx_pybuffer_lik_data;
  __pyx_pybuffer_probN_single.pybuffer.buf = NULL;
  __pyx_pybuffer_probN_single.refcount = 0;
  __pyx_pybuffernd_probN_single.data = NULL;
  __pyx_pybuffernd_probN_single.rcbuffer = &__pyx_pybuffer_probN_single;
  __pyx_pybuffer_dead_seqs.pybuffer.buf = NULL;
  __pyx_pybuffer_dead_seqs.refcount = 0;
  __pyx_pybuffernd_dead_seqs.data = NULL;
  __pyx_pybuffernd_dead_seqs.rcbuffer = &__pyx_pybuffer_dead_seqs;

  /* "_emirge_amplicon.pyx":82
 *     Cython helper function with typed data structures, fast looping.
 *     """
 *     t0 = time()             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_t0 = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":83
 *     """
 *     t0 = time()
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_bamfile_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 83, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_bamfile_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 83, __pyx_L1_error)
    } else {__pyx_pybuffernd_bamfile_data.diminfo[0].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bamfile_data.diminfo[0].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bamfile_data.diminfo[1].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bamfile_data.diminfo[1].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_4 = 0;
  __pyx_v_bamfile_data = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":84
 *     t0 = time()
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef list probN = em.probN
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 84, __pyx_L1_error)
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_reads = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 84, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads.diminfo[0].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads.diminfo[0].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_reads.diminfo[1].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_reads.diminfo[1].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_reads.diminfo[2].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_reads.diminfo[2].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_5 = 0;
  __pyx_v_reads = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":85
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals             # <<<<<<<<<<<<<<
 *     cdef list probN = em.probN
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_quals); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 85, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quals.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_quals = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 85, __pyx_L1_error)
    } else {__pyx_pybuffernd_quals.diminfo[0].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quals.diminfo[0].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quals.diminfo[1].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quals.diminfo[1].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quals.diminfo[2].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quals.diminfo[2].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_quals = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":86
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef list probN = em.probN             # <<<<<<<<<<<<<<
 * 
 *     # probN_array_of_pointers =
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 86, __pyx_L1_error)
  __pyx_v_probN = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":92
 *     # result arrays for constructing coo_matrix for likelihood.
 *     cdef bint paired_reads
 *     if em.reads2_filepath is not None:             # <<<<<<<<<<<<<<
 *         l = len(em.bamfile_data) / 2
 *         paired_reads = True
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads2_filepath); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = (__pyx_t_7 != 0);
  if (__pyx_t_8) {

    /* "_emirge_amplicon.pyx":93
 *     cdef bint paired_reads
 *     if em.reads2_filepath is not None:
 *         l = len(em.bamfile_data) / 2             # <<<<<<<<<<<<<<
 *         paired_reads = True
 *     else:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_bamfile_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 93, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_l = __Pyx_div_Py_ssize_t(__pyx_t_9, 2);

    /* "_emirge_amplicon.pyx":94
 *     if em.reads2_filepath is not None:
 *         l = len(em.bamfile_data) / 2
 *         paired_reads = True             # <<<<<<<<<<<<<<
 *     else:
 *         l = len(em.bamfile_data)
 */
    __pyx_v_paired_reads = 1;

    /* "_emirge_amplicon.pyx":92
 *     # result arrays for constructing coo_matrix for likelihood.
 *     cdef bint paired_reads
 *     if em.reads2_filepath is not None:             # <<<<<<<<<<<<<<
 *         l = len(em.bamfile_data) / 2
 *         paired_reads = True
 */
    goto __pyx_L3;
  }

  /* "_emirge_amplicon.pyx":96
 *         paired_reads = True
 *     else:
 *         l = len(em.bamfile_data)             # <<<<<<<<<<<<<<
 *         paired_reads = False
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_row_seqi  = np.empty(l, dtype=np.uint)
 */
  /*else*/ {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_bamfile_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 96, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_l = __pyx_t_9;

    /* "_emirge_amplicon.pyx":97
 *     else:
 *         l = len(em.bamfile_data)
 *         paired_reads = False             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_row_seqi  = np.empty(l, dtype=np.uint)
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_col_readi = np.empty_like(lik_row_seqi)
 */
    __pyx_v_paired_reads = 0;
  }
  __pyx_L3:;

  /* "_emirge_amplicon.pyx":98
 *         l = len(em.bamfile_data)
 *         paired_reads = False
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_row_seqi  = np.empty(l, dtype=np.uint)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_col_readi = np.empty_like(lik_row_seqi)
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data      = np.zeros(l, dtype=np.float)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_uint); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_11) < 0) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 98, __pyx_L1_error)
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_row_seqi = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 98, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_row_seqi.diminfo[0].strides = __pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_row_seqi.diminfo[0].shape = __pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_12 = 0;
  __pyx_v_lik_row_seqi = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "_emirge_amplicon.pyx":99
 *         paired_reads = False
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_row_seqi  = np.empty(l, dtype=np.uint)
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_col_readi = np.empty_like(lik_row_seqi)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data      = np.zeros(l, dtype=np.float)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty_like); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_lik_row_seqi)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 99, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_lik_row_seqi)};
      __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_11);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_lik_row_seqi)};
      __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_11);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_lik_row_seqi));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_row_seqi));
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, ((PyObject *)__pyx_v_lik_row_seqi));
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 99, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_col_readi = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 99, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_col_readi.diminfo[0].strides = __pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_col_readi.diminfo[0].shape = __pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_13 = 0;
  __pyx_v_lik_col_readi = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "_emirge_amplicon.pyx":100
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_row_seqi  = np.empty(l, dtype=np.uint)
 *     cdef np.ndarray[np.uint_t, ndim=1]  lik_col_readi = np.empty_like(lik_row_seqi)
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data      = np.zeros(l, dtype=np.float)             # <<<<<<<<<<<<<<
 * 
 *     cdef unsigned int alignedread_i
 */
  __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_l); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_11);
  __pyx_t_11 = 0;
  __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_dtype, __pyx_t_10) < 0) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (!(likely(((__pyx_t_10) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_10, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 100, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_10);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 100, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_data.diminfo[0].strides = __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_data.diminfo[0].shape = __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_14 = 0;
  __pyx_v_lik_data = ((PyArrayObject *)__pyx_t_10);
  __pyx_t_10 = 0;

  /* "_emirge_amplicon.pyx":123
 *     # of)  Assumption is that every two reads is a mapped pair spit out
 *     # from bowtie in bamfile
 *     cdef bint pair_collected = 1             # <<<<<<<<<<<<<<
 *     cdef unsigned int result_i       = 0
 *     cdef np.ndarray[np.float_t, ndim=2] probN_single  # an individual probN numpy matrix
 */
  __pyx_v_pair_collected = 1;

  /* "_emirge_amplicon.pyx":124
 *     # from bowtie in bamfile
 *     cdef bint pair_collected = 1
 *     cdef unsigned int result_i       = 0             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.float_t, ndim=2] probN_single  # an individual probN numpy matrix
 * 
 */
  __pyx_v_result_i = 0;

  /* "_emirge_amplicon.pyx":128
 * 
 *     cdef np.ndarray[np.uint8_t, ndim=1] dead_seqs # these sequences have been removed previously
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)             # <<<<<<<<<<<<<<
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:
 */
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_zeros); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = PyObject_Length(__pyx_t_10); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyInt_FromSsize_t(__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10);
  __pyx_t_10 = 0;
  __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_uint8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 128, __pyx_L1_error)
  __pyx_t_15 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
    __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_16 < 0)) {
      PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer, (PyObject*)__pyx_v_dead_seqs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
      }
    }
    __pyx_pybuffernd_dead_seqs.diminfo[0].strides = __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dead_seqs.diminfo[0].shape = __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 128, __pyx_L1_error)
  }
  __pyx_t_15 = 0;
  __pyx_v_dead_seqs = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":129
 *     cdef np.ndarray[np.uint8_t, ndim=1] dead_seqs # these sequences have been removed previously
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)
 *     for seq_i in range(len(em.probN)):             # <<<<<<<<<<<<<<
 *         if em.probN[seq_i] is None:
 *             dead_seqs[seq_i] = 1
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_9; __pyx_t_20+=1) {
    __pyx_v_seq_i = __pyx_t_20;

    /* "_emirge_amplicon.pyx":130
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:             # <<<<<<<<<<<<<<
 *             dead_seqs[seq_i] = 1
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_seq_i, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = (__pyx_t_10 == Py_None);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_7 = (__pyx_t_8 != 0);
    if (__pyx_t_7) {

      /* "_emirge_amplicon.pyx":131
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:
 *             dead_seqs[seq_i] = 1             # <<<<<<<<<<<<<<
 * 
 *     p = 0.0  # start off with no pair collected
 */
      __pyx_t_21 = __pyx_v_seq_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_dead_seqs.diminfo[0].strides) = 1;

      /* "_emirge_amplicon.pyx":130
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:             # <<<<<<<<<<<<<<
 *             dead_seqs[seq_i] = 1
 * 
 */
    }
  }

  /* "_emirge_amplicon.pyx":133
 *             dead_seqs[seq_i] = 1
 * 
 *     p = 0.0  # start off with no pair collected             # <<<<<<<<<<<<<<
 *     loop_t0 = time()
 *     for alignedread_i in range(bamfile_data.shape[0]):
 */
  __pyx_v_p = 0.0;

  /* "_emirge_amplicon.pyx":134
 * 
 *     p = 0.0  # start off with no pair collected
 *     loop_t0 = time()             # <<<<<<<<<<<<<<
 *     for alignedread_i in range(bamfile_data.shape[0]):
 *         if paired_reads:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 134, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 134, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_loop_t0 = __pyx_t_10;
  __pyx_t_10 = 0;

  /* "_emirge_amplicon.pyx":135
 *     p = 0.0  # start off with no pair collected
 *     loop_t0 = time()
 *     for alignedread_i in range(bamfile_data.shape[0]):             # <<<<<<<<<<<<<<
 *         if paired_reads:
 *             pair_collected = not pair_collected  # flip flag to indicate we've got 2/2 reads accumulated in p
 */
  __pyx_t_22 = (__pyx_v_bamfile_data->dimensions[0]);
  for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_22; __pyx_t_20+=1) {
    __pyx_v_alignedread_i = __pyx_t_20;

    /* "_emirge_amplicon.pyx":136
 *     loop_t0 = time()
 *     for alignedread_i in range(bamfile_data.shape[0]):
 *         if paired_reads:             # <<<<<<<<<<<<<<
 *             pair_collected = not pair_collected  # flip flag to indicate we've got 2/2 reads accumulated in p
 * 
 */
    __pyx_t_7 = (__pyx_v_paired_reads != 0);
    if (__pyx_t_7) {

      /* "_emirge_amplicon.pyx":137
 *     for alignedread_i in range(bamfile_data.shape[0]):
 *         if paired_reads:
 *             pair_collected = not pair_collected  # flip flag to indicate we've got 2/2 reads accumulated in p             # <<<<<<<<<<<<<<
 * 
 *         #   0       1       2      3     4       5   # "efficient indexing only affects certain index operations, namely those with exactly ndim number of typed integer indices
 */
      __pyx_v_pair_collected = (!(__pyx_v_pair_collected != 0));

      /* "_emirge_amplicon.pyx":136
 *     loop_t0 = time()
 *     for alignedread_i in range(bamfile_data.shape[0]):
 *         if paired_reads:             # <<<<<<<<<<<<<<
 *             pair_collected = not pair_collected  # flip flag to indicate we've got 2/2 reads accumulated in p
 * 
 */
    }

    /* "_emirge_amplicon.pyx":141
 *         #   0       1       2      3     4       5   # "efficient indexing only affects certain index operations, namely those with exactly ndim number of typed integer indices
 *         # seq_i, read_i, pair_i, rlen, pos, is_reverse = bamfile_data[alignedread_i]
 *         seq_i = bamfile_data[alignedread_i, 0]             # <<<<<<<<<<<<<<
 *         read_i = bamfile_data[alignedread_i, 1]
 * 
 */
    __pyx_t_23 = __pyx_v_alignedread_i;
    __pyx_t_24 = 0;
    if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_seq_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":142
 *         # seq_i, read_i, pair_i, rlen, pos, is_reverse = bamfile_data[alignedread_i]
 *         seq_i = bamfile_data[alignedread_i, 0]
 *         read_i = bamfile_data[alignedread_i, 1]             # <<<<<<<<<<<<<<
 * 
 *         if dead_seqs[seq_i]:
 */
    __pyx_t_25 = __pyx_v_alignedread_i;
    __pyx_t_26 = 1;
    if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_read_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":144
 *         read_i = bamfile_data[alignedread_i, 1]
 * 
 *         if dead_seqs[seq_i]:             # <<<<<<<<<<<<<<
 *             result = 0.0        # still store a result so that we can have th coo arrays allocated with right size.  These get ignored with sparse construction anyway
 *         else: # else this is a good seq_i
 */
    __pyx_t_27 = __pyx_v_seq_i;
    __pyx_t_7 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_dead_seqs.diminfo[0].strides)) != 0);
    if (__pyx_t_7) {

      /* "_emirge_amplicon.pyx":145
 * 
 *         if dead_seqs[seq_i]:
 *             result = 0.0        # still store a result so that we can have th coo arrays allocated with right size.  These get ignored with sparse construction anyway             # <<<<<<<<<<<<<<
 *         else: # else this is a good seq_i
 *             pair_i = bamfile_data[alignedread_i, 2]
 */
      __pyx_v_result = 0.0;

      /* "_emirge_amplicon.pyx":144
 *         read_i = bamfile_data[alignedread_i, 1]
 * 
 *         if dead_seqs[seq_i]:             # <<<<<<<<<<<<<<
 *             result = 0.0        # still store a result so that we can have th coo arrays allocated with right size.  These get ignored with sparse construction anyway
 *         else: # else this is a good seq_i
 */
      goto __pyx_L10;
    }

    /* "_emirge_amplicon.pyx":147
 *             result = 0.0        # still store a result so that we can have th coo arrays allocated with right size.  These get ignored with sparse construction anyway
 *         else: # else this is a good seq_i
 *             pair_i = bamfile_data[alignedread_i, 2]             # <<<<<<<<<<<<<<
 *             rlen = bamfile_data[alignedread_i, 3]
 *             pos = bamfile_data[alignedread_i, 4]
 */
    /*else*/ {
      __pyx_t_28 = __pyx_v_alignedread_i;
      __pyx_t_29 = 2;
      if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      __pyx_v_pair_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

      /* "_emirge_amplicon.pyx":148
 *         else: # else this is a good seq_i
 *             pair_i = bamfile_data[alignedread_i, 2]
 *             rlen = bamfile_data[alignedread_i, 3]             # <<<<<<<<<<<<<<
 *             pos = bamfile_data[alignedread_i, 4]
 *             is_reverse= bamfile_data[alignedread_i, 5]
 */
      __pyx_t_30 = __pyx_v_alignedread_i;
      __pyx_t_31 = 3;
      if (__pyx_t_31 < 0) __pyx_t_31 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      __pyx_v_rlen = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

      /* "_emirge_amplicon.pyx":149
 *             pair_i = bamfile_data[alignedread_i, 2]
 *             rlen = bamfile_data[alignedread_i, 3]
 *             pos = bamfile_data[alignedread_i, 4]             # <<<<<<<<<<<<<<
 *             is_reverse= bamfile_data[alignedread_i, 5]
 * 
 */
      __pyx_t_32 = __pyx_v_alignedread_i;
      __pyx_t_33 = 4;
      if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      __pyx_v_pos = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

      /* "_emirge_amplicon.pyx":150
 *             rlen = bamfile_data[alignedread_i, 3]
 *             pos = bamfile_data[alignedread_i, 4]
 *             is_reverse= bamfile_data[alignedread_i, 5]             # <<<<<<<<<<<<<<
 * 
 *             probN_single  = probN[seq_i]  # probably slow!! (list access)
 */
      __pyx_t_34 = __pyx_v_alignedread_i;
      __pyx_t_35 = 5;
      if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      __pyx_v_is_reverse = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_35, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

      /* "_emirge_amplicon.pyx":152
 *             is_reverse= bamfile_data[alignedread_i, 5]
 * 
 *             probN_single  = probN[seq_i]  # probably slow!! (list access)             # <<<<<<<<<<<<<<
 *             # probN_single = PyList_GET_ITEM(probN, seq_i)
 * 
 */
      if (unlikely(__pyx_v_probN == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 152, __pyx_L1_error)
      }
      if (!(likely(((PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i)) == Py_None) || likely(__Pyx_TypeTest(PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i), __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 152, __pyx_L1_error)
      __pyx_t_10 = PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i);
      __Pyx_INCREF(__pyx_t_10);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_10), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)__pyx_v_probN_single, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_17);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_19, __pyx_t_18, __pyx_t_17);
          }
        }
        __pyx_pybuffernd_probN_single.diminfo[0].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_probN_single.diminfo[0].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_probN_single.diminfo[1].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_probN_single.diminfo[1].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 152, __pyx_L1_error)
      }
      __Pyx_XDECREF_SET(__pyx_v_probN_single, ((PyArrayObject *)__pyx_t_10));
      __pyx_t_10 = 0;

      /* "_emirge_amplicon.pyx":155
 *             # probN_single = PyList_GET_ITEM(probN, seq_i)
 * 
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 # This code is redundant, but by basically manually inlining everything here in the special reverse-complement case, I gain some speed
 *                 for i in range(rlen):
 */
      __pyx_t_7 = (__pyx_v_is_reverse != 0);
      if (__pyx_t_7) {

        /* "_emirge_amplicon.pyx":157
 *             if is_reverse:
 *                 # This code is redundant, but by basically manually inlining everything here in the special reverse-complement case, I gain some speed
 *                 for i in range(rlen):             # <<<<<<<<<<<<<<
 *                     ii = rlen-1-i
 *                     s = 0.0
 */
        __pyx_t_36 = __pyx_v_rlen;
        for (__pyx_t_37 = 0; __pyx_t_37 < __pyx_t_36; __pyx_t_37+=1) {
          __pyx_v_i = __pyx_t_37;

          /* "_emirge_amplicon.pyx":158
 *                 # This code is redundant, but by basically manually inlining everything here in the special reverse-complement case, I gain some speed
 *                 for i in range(rlen):
 *                     ii = rlen-1-i             # <<<<<<<<<<<<<<
 *                     s = 0.0
 *                     for j in range(4):
 */
          __pyx_v_ii = ((__pyx_v_rlen - 1) - __pyx_v_i);

          /* "_emirge_amplicon.pyx":159
 *                 for i in range(rlen):
 *                     ii = rlen-1-i
 *                     s = 0.0             # <<<<<<<<<<<<<<
 *                     for j in range(4):
 *                         if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, set 1-P
 */
          __pyx_v_s = 0.0;

          /* "_emirge_amplicon.pyx":160
 *                     ii = rlen-1-i
 *                     s = 0.0
 *                     for j in range(4):             # <<<<<<<<<<<<<<
 *                         if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, set 1-P
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 */
          for (__pyx_t_38 = 0; __pyx_t_38 < 4; __pyx_t_38+=1) {
            __pyx_v_j = __pyx_t_38;

            /* "_emirge_amplicon.pyx":161
 *                     s = 0.0
 *                     for j in range(4):
 *                         if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, set 1-P             # <<<<<<<<<<<<<<
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * probN_single[pos + i, j] )    # lookup table
 */
            __pyx_t_39 = __pyx_v_read_i;
            __pyx_t_40 = __pyx_v_pair_i;
            __pyx_t_41 = __pyx_v_ii;
            __pyx_t_7 = ((__pyx_f_16_emirge_amplicon_complement_numeric_base((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf, __pyx_t_39, __pyx_pybuffernd_reads.diminfo[0].strides, __pyx_t_40, __pyx_pybuffernd_reads.diminfo[1].strides, __pyx_t_41, __pyx_pybuffernd_reads.diminfo[2].strides))) == __pyx_v_j) != 0);
            if (__pyx_t_7) {

              /* "_emirge_amplicon.pyx":163
 *                         if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, set 1-P
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * probN_single[pos + i, j] )    # lookup table             # <<<<<<<<<<<<<<
 *                         else:                       # this is not the called base, so set to P/3
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 */
              __pyx_t_42 = __pyx_v_read_i;
              __pyx_t_43 = __pyx_v_pair_i;
              __pyx_t_44 = __pyx_v_ii;
              __pyx_t_45 = (__pyx_v_pos + __pyx_v_i);
              __pyx_t_46 = __pyx_v_j;
              __pyx_v_s = (__pyx_v_s + ((qual2one_minus_p[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_42, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_43, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_44, __pyx_pybuffernd_quals.diminfo[2].strides))]) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_45, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_46, __pyx_pybuffernd_probN_single.diminfo[1].strides))));

              /* "_emirge_amplicon.pyx":161
 *                     s = 0.0
 *                     for j in range(4):
 *                         if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, set 1-P             # <<<<<<<<<<<<<<
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * probN_single[pos + i, j] )    # lookup table
 */
              goto __pyx_L16;
            }

            /* "_emirge_amplicon.pyx":166
 *                         else:                       # this is not the called base, so set to P/3
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, ii]] * probN_single[pos + i, j] )          # lookup table             # <<<<<<<<<<<<<<
 *                     p += log(s)
 * 
 */
            /*else*/ {
              __pyx_t_47 = __pyx_v_read_i;
              __pyx_t_48 = __pyx_v_pair_i;
              __pyx_t_49 = __pyx_v_ii;
              __pyx_t_50 = (__pyx_v_pos + __pyx_v_i);
              __pyx_t_51 = __pyx_v_j;
              __pyx_v_s = (__pyx_v_s + ((qual2p_div_3[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_47, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_48, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_49, __pyx_pybuffernd_quals.diminfo[2].strides))]) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_50, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_51, __pyx_pybuffernd_probN_single.diminfo[1].strides))));
            }
            __pyx_L16:;
          }

          /* "_emirge_amplicon.pyx":167
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, ii]] * probN_single[pos + i, j] )          # lookup table
 *                     p += log(s)             # <<<<<<<<<<<<<<
 * 
 *             else: # not reverse
 */
          __pyx_v_p = (__pyx_v_p + log(__pyx_v_s));
        }

        /* "_emirge_amplicon.pyx":155
 *             # probN_single = PyList_GET_ITEM(probN, seq_i)
 * 
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 # This code is redundant, but by basically manually inlining everything here in the special reverse-complement case, I gain some speed
 *                 for i in range(rlen):
 */
        goto __pyx_L11;
      }

      /* "_emirge_amplicon.pyx":170
 * 
 *             else: # not reverse
 *                 for i in range(rlen):             # <<<<<<<<<<<<<<
 *                     s = 0.0
 *                     for j in range(4):
 */
      /*else*/ {
        __pyx_t_36 = __pyx_v_rlen;
        for (__pyx_t_37 = 0; __pyx_t_37 < __pyx_t_36; __pyx_t_37+=1) {
          __pyx_v_i = __pyx_t_37;

          /* "_emirge_amplicon.pyx":171
 *             else: # not reverse
 *                 for i in range(rlen):
 *                     s = 0.0             # <<<<<<<<<<<<<<
 *                     for j in range(4):
 *                         if reads[read_i, pair_i, i] == j:   # this is called base, set 1-P
 */
          __pyx_v_s = 0.0;

          /* "_emirge_amplicon.pyx":172
 *                 for i in range(rlen):
 *                     s = 0.0
 *                     for j in range(4):             # <<<<<<<<<<<<<<
 *                         if reads[read_i, pair_i, i] == j:   # this is called base, set 1-P
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 */
          for (__pyx_t_38 = 0; __pyx_t_38 < 4; __pyx_t_38+=1) {
            __pyx_v_j = __pyx_t_38;

            /* "_emirge_amplicon.pyx":173
 *                     s = 0.0
 *                     for j in range(4):
 *                         if reads[read_i, pair_i, i] == j:   # this is called base, set 1-P             # <<<<<<<<<<<<<<
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )    # lookup table
 */
            __pyx_t_52 = __pyx_v_read_i;
            __pyx_t_53 = __pyx_v_pair_i;
            __pyx_t_54 = __pyx_v_i;
            __pyx_t_7 = (((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf, __pyx_t_52, __pyx_pybuffernd_reads.diminfo[0].strides, __pyx_t_53, __pyx_pybuffernd_reads.diminfo[1].strides, __pyx_t_54, __pyx_pybuffernd_reads.diminfo[2].strides)) == __pyx_v_j) != 0);
            if (__pyx_t_7) {

              /* "_emirge_amplicon.pyx":175
 *                         if reads[read_i, pair_i, i] == j:   # this is called base, set 1-P
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )    # lookup table             # <<<<<<<<<<<<<<
 *                         else:                       # this is not the called base, so set to P/3
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 */
              __pyx_t_55 = __pyx_v_read_i;
              __pyx_t_56 = __pyx_v_pair_i;
              __pyx_t_57 = __pyx_v_i;
              __pyx_t_58 = (__pyx_v_pos + __pyx_v_i);
              __pyx_t_59 = __pyx_v_j;
              __pyx_v_s = (__pyx_v_s + ((qual2one_minus_p[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_55, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_56, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_57, __pyx_pybuffernd_quals.diminfo[2].strides))]) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_58, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_59, __pyx_pybuffernd_probN_single.diminfo[1].strides))));

              /* "_emirge_amplicon.pyx":173
 *                     s = 0.0
 *                     for j in range(4):
 *                         if reads[read_i, pair_i, i] == j:   # this is called base, set 1-P             # <<<<<<<<<<<<<<
 *                             # s += (1. - error_p_i) * probN[pos + i, j]
 *                             s += ( qual2one_minus_p[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )    # lookup table
 */
              goto __pyx_L21;
            }

            /* "_emirge_amplicon.pyx":178
 *                         else:                       # this is not the called base, so set to P/3
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )          # lookup table             # <<<<<<<<<<<<<<
 *                     p += log(s)
 *             if pair_collected:
 */
            /*else*/ {
              __pyx_t_60 = __pyx_v_read_i;
              __pyx_t_61 = __pyx_v_pair_i;
              __pyx_t_62 = __pyx_v_i;
              __pyx_t_63 = (__pyx_v_pos + __pyx_v_i);
              __pyx_t_64 = __pyx_v_j;
              __pyx_v_s = (__pyx_v_s + ((qual2p_div_3[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_60, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_61, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_62, __pyx_pybuffernd_quals.diminfo[2].strides))]) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_63, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_64, __pyx_pybuffernd_probN_single.diminfo[1].strides))));
            }
            __pyx_L21:;
          }

          /* "_emirge_amplicon.pyx":179
 *                             # s += (error_p_i / 3 ) * probN[pos + i, j]
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )          # lookup table
 *                     p += log(s)             # <<<<<<<<<<<<<<
 *             if pair_collected:
 *                 result = c_pow(M_E, p)
 */
          __pyx_v_p = (__pyx_v_p + log(__pyx_v_s));
        }
      }
      __pyx_L11:;

      /* "_emirge_amplicon.pyx":180
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )          # lookup table
 *                     p += log(s)
 *             if pair_collected:             # <<<<<<<<<<<<<<
 *                 result = c_pow(M_E, p)
 * 
 */
      __pyx_t_7 = (__pyx_v_pair_collected != 0);
      if (__pyx_t_7) {

        /* "_emirge_amplicon.pyx":181
 *                     p += log(s)
 *             if pair_collected:
 *                 result = c_pow(M_E, p)             # <<<<<<<<<<<<<<
 * 
 *         if pair_collected:
 */
        __pyx_v_result = pow(M_E, __pyx_v_p);

        /* "_emirge_amplicon.pyx":180
 *                             s += ( qual2p_div_3[quals[read_i, pair_i, i]] * probN_single[pos + i, j] )          # lookup table
 *                     p += log(s)
 *             if pair_collected:             # <<<<<<<<<<<<<<
 *                 result = c_pow(M_E, p)
 * 
 */
      }
    }
    __pyx_L10:;

    /* "_emirge_amplicon.pyx":183
 *                 result = c_pow(M_E, p)
 * 
 *         if pair_collected:             # <<<<<<<<<<<<<<
 *             # for either good seq or dead seq, add the values to the coo construction arrays
 *             lik_row_seqi[result_i] = seq_i
 */
    __pyx_t_7 = (__pyx_v_pair_collected != 0);
    if (__pyx_t_7) {

      /* "_emirge_amplicon.pyx":185
 *         if pair_collected:
 *             # for either good seq or dead seq, add the values to the coo construction arrays
 *             lik_row_seqi[result_i] = seq_i             # <<<<<<<<<<<<<<
 *             lik_col_readi[result_i] = read_i
 *             lik_data[result_i] = result
 */
      __pyx_t_65 = __pyx_v_result_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint_t *, __pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer.buf, __pyx_t_65, __pyx_pybuffernd_lik_row_seqi.diminfo[0].strides) = __pyx_v_seq_i;

      /* "_emirge_amplicon.pyx":186
 *             # for either good seq or dead seq, add the values to the coo construction arrays
 *             lik_row_seqi[result_i] = seq_i
 *             lik_col_readi[result_i] = read_i             # <<<<<<<<<<<<<<
 *             lik_data[result_i] = result
 *             p = 0.0  # reset for next pair or single read
 */
      __pyx_t_66 = __pyx_v_result_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint_t *, __pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer.buf, __pyx_t_66, __pyx_pybuffernd_lik_col_readi.diminfo[0].strides) = __pyx_v_read_i;

      /* "_emirge_amplicon.pyx":187
 *             lik_row_seqi[result_i] = seq_i
 *             lik_col_readi[result_i] = read_i
 *             lik_data[result_i] = result             # <<<<<<<<<<<<<<
 *             p = 0.0  # reset for next pair or single read
 *             result_i += 1
 */
      __pyx_t_67 = __pyx_v_result_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.buf, __pyx_t_67, __pyx_pybuffernd_lik_data.diminfo[0].strides) = __pyx_v_result;

      /* "_emirge_amplicon.pyx":188
 *             lik_col_readi[result_i] = read_i
 *             lik_data[result_i] = result
 *             p = 0.0  # reset for next pair or single read             # <<<<<<<<<<<<<<
 *             result_i += 1
 *     td = timedelta(seconds = time()-loop_t0)
 */
      __pyx_v_p = 0.0;

      /* "_emirge_amplicon.pyx":189
 *             lik_data[result_i] = result
 *             p = 0.0  # reset for next pair or single read
 *             result_i += 1             # <<<<<<<<<<<<<<
 *     td = timedelta(seconds = time()-loop_t0)
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_likelihood time per 1000 bam entries: %.2e seconds"%(em.iteration_i, (((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)) / alignedread_i) * 1000.0) # DEBUG
 */
      __pyx_v_result_i = (__pyx_v_result_i + 1);

      /* "_emirge_amplicon.pyx":183
 *                 result = c_pow(M_E, p)
 * 
 *         if pair_collected:             # <<<<<<<<<<<<<<
 *             # for either good seq or dead seq, add the values to the coo construction arrays
 *             lik_row_seqi[result_i] = seq_i
 */
    }
  }

  /* "_emirge_amplicon.pyx":190
 *             p = 0.0  # reset for next pair or single read
 *             result_i += 1
 *     td = timedelta(seconds = time()-loop_t0)             # <<<<<<<<<<<<<<
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_likelihood time per 1000 bam entries: %.2e seconds"%(em.iteration_i, (((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)) / alignedread_i) * 1000.0) # DEBUG
 *     # now actually construct sparse matrix.
 */
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_timedelta); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyNumber_Subtract(__pyx_t_2, __pyx_v_loop_t0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_seconds, __pyx_t_11) < 0) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_td = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "_emirge_amplicon.pyx":193
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_likelihood time per 1000 bam entries: %.2e seconds"%(em.iteration_i, (((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)) / alignedread_i) * 1000.0) # DEBUG
 *     # now actually construct sparse matrix.
 *     em.likelihoods = sparse.coo_matrix((lik_data, (lik_row_seqi, lik_col_readi)), em.likelihoods.shape, dtype=em.likelihoods.dtype).tocsr()             # <<<<<<<<<<<<<<
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_likelihood total cython function call time: %s seconds"%(em.iteration_i, timedelta(seconds = time()-t0)) # DEBUG
 *     return
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sparse); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_coo_matrix); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_lik_row_seqi));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_row_seqi));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_lik_row_seqi));
  __Pyx_INCREF(((PyObject *)__pyx_v_lik_col_readi));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_col_readi));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_lik_col_readi));
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_lik_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_data));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_lik_data));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_likelihoods); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_likelihoods); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_68 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dtype); if (unlikely(!__pyx_t_68)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_68);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_68) < 0) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_68); __pyx_t_68 = 0;
  __pyx_t_68 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_68)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_68);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_68, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_68); __pyx_t_68 = 0;
  __pyx_t_68 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_68 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_68)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_68);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_68) {
    __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_68); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 193, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_68); __pyx_t_68 = 0;
  } else {
    __pyx_t_11 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 193, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_em, __pyx_n_s_likelihoods, __pyx_t_11) < 0) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "_emirge_amplicon.pyx":195
 *     em.likelihoods = sparse.coo_matrix((lik_data, (lik_row_seqi, lik_col_readi)), em.likelihoods.shape, dtype=em.likelihoods.dtype).tocsr()
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_likelihood total cython function call time: %s seconds"%(em.iteration_i, timedelta(seconds = time()-t0)) # DEBUG
 *     return             # <<<<<<<<<<<<<<
 * 
 * @cython.boundscheck(False)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":78
 * 
 * @cython.boundscheck(False)
 * def _calc_likelihood(em):             # <<<<<<<<<<<<<<
 *     """
 *     Cython helper function with typed data structures, fast looping.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_68);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon._calc_likelihood", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_col_readi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_row_seqi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_t0);
  __Pyx_XDECREF((PyObject *)__pyx_v_bamfile_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_reads);
  __Pyx_XDECREF((PyObject *)__pyx_v_quals);
  __Pyx_XDECREF(__pyx_v_probN);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_row_seqi);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_col_readi);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_probN_single);
  __Pyx_XDECREF((PyObject *)__pyx_v_dead_seqs);
  __Pyx_XDECREF(__pyx_v_loop_t0);
  __Pyx_XDECREF(__pyx_v_td);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":198
 * 
 * @cython.boundscheck(False)
 * def _calc_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     helper function to emirge_amplicon.py calc_probN
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_3_calc_probN(PyObject *__pyx_self, PyObject *__pyx_v_em); /*proto*/
static char __pyx_doc_16_emirge_amplicon_2_calc_probN[] = "\n    helper function to emirge_amplicon.py calc_probN\n    \n    calculates effect of *all* reads on probN\n    i.e. loop over entire bamfile_data.\n    \n    ON RETURN:  probN contains sums of weighted prob vals\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_3_calc_probN = {"_calc_probN", (PyCFunction)__pyx_pw_16_emirge_amplicon_3_calc_probN, METH_O, __pyx_doc_16_emirge_amplicon_2_calc_probN};
static PyObject *__pyx_pw_16_emirge_amplicon_3_calc_probN(PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calc_probN (wrapper)", 0);
  __pyx_r = __pyx_pf_16_emirge_amplicon_2_calc_probN(__pyx_self, ((PyObject *)__pyx_v_em));

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

static PyObject *__pyx_pf_16_emirge_amplicon_2_calc_probN(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em) {
  int __pyx_v_initial_iteration;
  PyArrayObject *__pyx_v_reads = 0;
  PyArrayObject *__pyx_v_quals = 0;
  PyArrayObject *__pyx_v_bamfile_data = 0;
  PyArrayObject *__pyx_v_priors = 0;
  PyArrayObject *__pyx_v_posteriors_data = 0;
  PyArrayObject *__pyx_v_posteriors_indices = 0;
  PyArrayObject *__pyx_v_posteriors_indptr = 0;
  CYTHON_UNUSED PyObject *__pyx_v_convert_t0 = NULL;
  PyObject *__pyx_v_posteriors = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_t_check = NULL;
  PyObject *__pyx_v_probN = 0;
  unsigned int __pyx_v_alignedread_i;
  unsigned int __pyx_v_seq_i;
  unsigned int __pyx_v_read_i;
  unsigned int __pyx_v_pair_i;
  unsigned int __pyx_v_rlen;
  unsigned int __pyx_v_pos;
  int __pyx_v_is_reverse;
  unsigned int __pyx_v_i;
  unsigned int __pyx_v_ii;
  unsigned int __pyx_v_j;
  int __pyx_v_mid;
  int __pyx_v_hi;
  int __pyx_v_midval;
  double __pyx_v_weight;
  PyArrayObject *__pyx_v_probN_single = 0;
  PyArrayObject *__pyx_v_reads_seen = 0;
  PyArrayObject *__pyx_v_reads_seen_this_round = 0;
  PyArrayObject *__pyx_v_dead_seqs = 0;
  PyObject *__pyx_v_loop_t0 = NULL;
  PyObject *__pyx_v_lo = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_td = NULL;
  double __pyx_v_base_sum;
  PyArrayObject *__pyx_v_seq_bases = 0;
  PyArrayObject *__pyx_v_unmapped_bases = 0;
  char *__pyx_v_seq;
  unsigned short __pyx_v_reference_base;
  double __pyx_v_one_minus_p;
  double __pyx_v_p_div_3;
  PyObject *__pyx_v_sequence_i2sequence_name_array = NULL;
  PyObject *__pyx_v_py_seq = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bamfile_data;
  __Pyx_Buffer __pyx_pybuffer_bamfile_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_dead_seqs;
  __Pyx_Buffer __pyx_pybuffer_dead_seqs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_posteriors_data;
  __Pyx_Buffer __pyx_pybuffer_posteriors_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_posteriors_indices;
  __Pyx_Buffer __pyx_pybuffer_posteriors_indices;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_posteriors_indptr;
  __Pyx_Buffer __pyx_pybuffer_posteriors_indptr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_priors;
  __Pyx_Buffer __pyx_pybuffer_priors;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_probN_single;
  __Pyx_Buffer __pyx_pybuffer_probN_single;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_quals;
  __Pyx_Buffer __pyx_pybuffer_quals;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads;
  __Pyx_Buffer __pyx_pybuffer_reads;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads_seen;
  __Pyx_Buffer __pyx_pybuffer_reads_seen;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads_seen_this_round;
  __Pyx_Buffer __pyx_pybuffer_reads_seen_this_round;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_seq_bases;
  __Pyx_Buffer __pyx_pybuffer_seq_bases;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_unmapped_bases;
  __Pyx_Buffer __pyx_pybuffer_unmapped_bases;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyArrayObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyArrayObject *__pyx_t_16 = NULL;
  PyArrayObject *__pyx_t_17 = NULL;
  PyArrayObject *__pyx_t_18 = NULL;
  PyArrayObject *__pyx_t_19 = NULL;
  Py_ssize_t __pyx_t_20;
  PyArrayObject *__pyx_t_21 = NULL;
  unsigned int __pyx_t_22;
  int __pyx_t_23;
  size_t __pyx_t_24;
  npy_intp __pyx_t_25;
  size_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  size_t __pyx_t_28;
  size_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  size_t __pyx_t_31;
  Py_ssize_t __pyx_t_32;
  size_t __pyx_t_33;
  Py_ssize_t __pyx_t_34;
  size_t __pyx_t_35;
  Py_ssize_t __pyx_t_36;
  size_t __pyx_t_37;
  Py_ssize_t __pyx_t_38;
  size_t __pyx_t_39;
  size_t __pyx_t_40;
  size_t __pyx_t_41;
  size_t __pyx_t_42;
  size_t __pyx_t_43;
  Py_ssize_t __pyx_t_44;
  Py_ssize_t __pyx_t_45;
  Py_ssize_t __pyx_t_46;
  unsigned int __pyx_t_47;
  unsigned int __pyx_t_48;
  unsigned int __pyx_t_49;
  size_t __pyx_t_50;
  size_t __pyx_t_51;
  size_t __pyx_t_52;
  size_t __pyx_t_53;
  size_t __pyx_t_54;
  size_t __pyx_t_55;
  size_t __pyx_t_56;
  size_t __pyx_t_57;
  size_t __pyx_t_58;
  size_t __pyx_t_59;
  size_t __pyx_t_60;
  size_t __pyx_t_61;
  size_t __pyx_t_62;
  size_t __pyx_t_63;
  size_t __pyx_t_64;
  size_t __pyx_t_65;
  size_t __pyx_t_66;
  size_t __pyx_t_67;
  size_t __pyx_t_68;
  size_t __pyx_t_69;
  size_t __pyx_t_70;
  size_t __pyx_t_71;
  size_t __pyx_t_72;
  size_t __pyx_t_73;
  size_t __pyx_t_74;
  size_t __pyx_t_75;
  double __pyx_t_76;
  PyObject *(*__pyx_t_77)(PyObject *);
  PyArrayObject *__pyx_t_78 = NULL;
  PyObject *__pyx_t_79 = NULL;
  char *__pyx_t_80;
  Py_ssize_t __pyx_t_81;
  PyArrayObject *__pyx_t_82 = NULL;
  size_t __pyx_t_83;
  size_t __pyx_t_84;
  size_t __pyx_t_85;
  size_t __pyx_t_86;
  size_t __pyx_t_87;
  size_t __pyx_t_88;
  size_t __pyx_t_89;
  size_t __pyx_t_90;
  size_t __pyx_t_91;
  size_t __pyx_t_92;
  __pyx_t_5numpy_float_t __pyx_t_93;
  size_t __pyx_t_94;
  size_t __pyx_t_95;
  __Pyx_RefNannySetupContext("_calc_probN", 0);
  __pyx_pybuffer_reads.pybuffer.buf = NULL;
  __pyx_pybuffer_reads.refcount = 0;
  __pyx_pybuffernd_reads.data = NULL;
  __pyx_pybuffernd_reads.rcbuffer = &__pyx_pybuffer_reads;
  __pyx_pybuffer_quals.pybuffer.buf = NULL;
  __pyx_pybuffer_quals.refcount = 0;
  __pyx_pybuffernd_quals.data = NULL;
  __pyx_pybuffernd_quals.rcbuffer = &__pyx_pybuffer_quals;
  __pyx_pybuffer_bamfile_data.pybuffer.buf = NULL;
  __pyx_pybuffer_bamfile_data.refcount = 0;
  __pyx_pybuffernd_bamfile_data.data = NULL;
  __pyx_pybuffernd_bamfile_data.rcbuffer = &__pyx_pybuffer_bamfile_data;
  __pyx_pybuffer_priors.pybuffer.buf = NULL;
  __pyx_pybuffer_priors.refcount = 0;
  __pyx_pybuffernd_priors.data = NULL;
  __pyx_pybuffernd_priors.rcbuffer = &__pyx_pybuffer_priors;
  __pyx_pybuffer_posteriors_data.pybuffer.buf = NULL;
  __pyx_pybuffer_posteriors_data.refcount = 0;
  __pyx_pybuffernd_posteriors_data.data = NULL;
  __pyx_pybuffernd_posteriors_data.rcbuffer = &__pyx_pybuffer_posteriors_data;
  __pyx_pybuffer_posteriors_indices.pybuffer.buf = NULL;
  __pyx_pybuffer_posteriors_indices.refcount = 0;
  __pyx_pybuffernd_posteriors_indices.data = NULL;
  __pyx_pybuffernd_posteriors_indices.rcbuffer = &__pyx_pybuffer_posteriors_indices;
  __pyx_pybuffer_posteriors_indptr.pybuffer.buf = NULL;
  __pyx_pybuffer_posteriors_indptr.refcount = 0;
  __pyx_pybuffernd_posteriors_indptr.data = NULL;
  __pyx_pybuffernd_posteriors_indptr.rcbuffer = &__pyx_pybuffer_posteriors_indptr;
  __pyx_pybuffer_probN_single.pybuffer.buf = NULL;
  __pyx_pybuffer_probN_single.refcount = 0;
  __pyx_pybuffernd_probN_single.data = NULL;
  __pyx_pybuffernd_probN_single.rcbuffer = &__pyx_pybuffer_probN_single;
  __pyx_pybuffer_reads_seen.pybuffer.buf = NULL;
  __pyx_pybuffer_reads_seen.refcount = 0;
  __pyx_pybuffernd_reads_seen.data = NULL;
  __pyx_pybuffernd_reads_seen.rcbuffer = &__pyx_pybuffer_reads_seen;
  __pyx_pybuffer_reads_seen_this_round.pybuffer.buf = NULL;
  __pyx_pybuffer_reads_seen_this_round.refcount = 0;
  __pyx_pybuffernd_reads_seen_this_round.data = NULL;
  __pyx_pybuffernd_reads_seen_this_round.rcbuffer = &__pyx_pybuffer_reads_seen_this_round;
  __pyx_pybuffer_dead_seqs.pybuffer.buf = NULL;
  __pyx_pybuffer_dead_seqs.refcount = 0;
  __pyx_pybuffernd_dead_seqs.data = NULL;
  __pyx_pybuffernd_dead_seqs.rcbuffer = &__pyx_pybuffer_dead_seqs;
  __pyx_pybuffer_seq_bases.pybuffer.buf = NULL;
  __pyx_pybuffer_seq_bases.refcount = 0;
  __pyx_pybuffernd_seq_bases.data = NULL;
  __pyx_pybuffernd_seq_bases.rcbuffer = &__pyx_pybuffer_seq_bases;
  __pyx_pybuffer_unmapped_bases.pybuffer.buf = NULL;
  __pyx_pybuffer_unmapped_bases.refcount = 0;
  __pyx_pybuffernd_unmapped_bases.data = NULL;
  __pyx_pybuffernd_unmapped_bases.rcbuffer = &__pyx_pybuffer_unmapped_bases;

  /* "_emirge_amplicon.pyx":207
 *     ON RETURN:  probN contains sums of weighted prob vals
 *     """
 *     cdef bint initial_iteration = em.iteration_i < 1#  or em.resume   # MARK if resume case, no posteriors, so treat like initial iter and use priors.             # <<<<<<<<<<<<<<
 * 
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # shape = (self.n_reads, 2, self.max_read_length) (dim 1 = pair)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_iteration_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 207, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 207, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_initial_iteration = __pyx_t_3;

  /* "_emirge_amplicon.pyx":209
 *     cdef bint initial_iteration = em.iteration_i < 1#  or em.resume   # MARK if resume case, no posteriors, so treat like initial iter and use priors.
 * 
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # shape = (self.n_reads, 2, self.max_read_length) (dim 1 = pair)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 209, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_reads = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 209, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads.diminfo[0].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads.diminfo[0].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_reads.diminfo[1].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_reads.diminfo[1].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_reads.diminfo[2].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_reads.diminfo[2].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_4 = 0;
  __pyx_v_reads = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":210
 * 
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # shape = (self.n_reads, 2, self.max_read_length) (dim 1 = pair)
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_quals); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 210, __pyx_L1_error)
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quals.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_quals = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 210, __pyx_L1_error)
    } else {__pyx_pybuffernd_quals.diminfo[0].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quals.diminfo[0].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quals.diminfo[1].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quals.diminfo[1].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quals.diminfo[2].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quals.diminfo[2].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_5 = 0;
  __pyx_v_quals = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":211
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # shape = (self.n_reads, 2, self.max_read_length) (dim 1 = pair)
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data = em.bamfile_data             # <<<<<<<<<<<<<<
 * 
 *     # if no posteriors are present (or initial iter), falls back on priors from previous round
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_bamfile_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 211, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_bamfile_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 211, __pyx_L1_error)
    } else {__pyx_pybuffernd_bamfile_data.diminfo[0].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bamfile_data.diminfo[0].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bamfile_data.diminfo[1].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bamfile_data.diminfo[1].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_bamfile_data = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":214
 * 
 *     # if no posteriors are present (or initial iter), falls back on priors from previous round
 *     cdef np.ndarray[np.float_t, ndim=1] priors = np.array(em.priors[-2], dtype = np.float)             # <<<<<<<<<<<<<<
 * 
 *     ## posteriors is a sparse matrix, so this presents a little bit of a tricky situation until
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_priors); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_2, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_9) < 0) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 214, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_9);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_priors.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_priors = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_priors.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 214, __pyx_L1_error)
    } else {__pyx_pybuffernd_priors.diminfo[0].strides = __pyx_pybuffernd_priors.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_priors.diminfo[0].shape = __pyx_pybuffernd_priors.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_priors = ((PyArrayObject *)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "_emirge_amplicon.pyx":225
 *     cdef np.ndarray[np.int32_t, ndim=1] posteriors_indptr
 * 
 *     if not initial_iteration:             # <<<<<<<<<<<<<<
 *         convert_t0 = time()
 *         em.posteriors[-2] = em.posteriors[-2].tocsr()
 */
  __pyx_t_3 = ((!(__pyx_v_initial_iteration != 0)) != 0);
  if (__pyx_t_3) {

    /* "_emirge_amplicon.pyx":226
 * 
 *     if not initial_iteration:
 *         convert_t0 = time()             # <<<<<<<<<<<<<<
 *         em.posteriors[-2] = em.posteriors[-2].tocsr()
 *         em.posteriors[-2].sort_indices()
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 226, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_convert_t0 = __pyx_t_9;
    __pyx_t_9 = 0;

    /* "_emirge_amplicon.pyx":227
 *     if not initial_iteration:
 *         convert_t0 = time()
 *         em.posteriors[-2] = em.posteriors[-2].tocsr()             # <<<<<<<<<<<<<<
 *         em.posteriors[-2].sort_indices()
 *         # print >> sys.stderr, "DEBUG: Time for conversion of posterios to csr sparse matrix: %s"%(timedelta(seconds = time() - convert_t0))
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_7, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 227, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(__Pyx_SetItemInt(__pyx_t_7, -2L, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 0) < 0)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "_emirge_amplicon.pyx":228
 *         convert_t0 = time()
 *         em.posteriors[-2] = em.posteriors[-2].tocsr()
 *         em.posteriors[-2].sort_indices()             # <<<<<<<<<<<<<<
 *         # print >> sys.stderr, "DEBUG: Time for conversion of posterios to csr sparse matrix: %s"%(timedelta(seconds = time() - convert_t0))
 *         posteriors = em.posteriors[-2]  # this depends on PREVIOUS iteration's posteriors (seq_n x read_n)
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_7, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sort_indices); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 228, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 228, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "_emirge_amplicon.pyx":230
 *         em.posteriors[-2].sort_indices()
 *         # print >> sys.stderr, "DEBUG: Time for conversion of posterios to csr sparse matrix: %s"%(timedelta(seconds = time() - convert_t0))
 *         posteriors = em.posteriors[-2]  # this depends on PREVIOUS iteration's posteriors (seq_n x read_n)             # <<<<<<<<<<<<<<
 *         posteriors_data = posteriors.data
 *         posteriors_indices = posteriors.indices
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_9, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_posteriors = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "_emirge_amplicon.pyx":231
 *         # print >> sys.stderr, "DEBUG: Time for conversion of posterios to csr sparse matrix: %s"%(timedelta(seconds = time() - convert_t0))
 *         posteriors = em.posteriors[-2]  # this depends on PREVIOUS iteration's posteriors (seq_n x read_n)
 *         posteriors_data = posteriors.data             # <<<<<<<<<<<<<<
 *         posteriors_indices = posteriors.indices
 *         posteriors_indptr = posteriors.indptr
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_posteriors, __pyx_n_s_data); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 231, __pyx_L1_error)
    __pyx_t_11 = ((PyArrayObject *)__pyx_t_7);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_posteriors_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        }
      }
      __pyx_pybuffernd_posteriors_data.diminfo[0].strides = __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_posteriors_data.diminfo[0].shape = __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 231, __pyx_L1_error)
    }
    __pyx_t_11 = 0;
    __pyx_v_posteriors_data = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "_emirge_amplicon.pyx":232
 *         posteriors = em.posteriors[-2]  # this depends on PREVIOUS iteration's posteriors (seq_n x read_n)
 *         posteriors_data = posteriors.data
 *         posteriors_indices = posteriors.indices             # <<<<<<<<<<<<<<
 *         posteriors_indptr = posteriors.indptr
 *     else:
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_posteriors, __pyx_n_s_indices); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 232, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_7);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer, (PyObject*)__pyx_v_posteriors_indices, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_posteriors_indices.diminfo[0].strides = __pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_posteriors_indices.diminfo[0].shape = __pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 232, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __pyx_v_posteriors_indices = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "_emirge_amplicon.pyx":233
 *         posteriors_data = posteriors.data
 *         posteriors_indices = posteriors.indices
 *         posteriors_indptr = posteriors.indptr             # <<<<<<<<<<<<<<
 *     else:
 *         posteriors = None
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_posteriors, __pyx_n_s_indptr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 233, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 233, __pyx_L1_error)
    __pyx_t_17 = ((PyArrayObject *)__pyx_t_7);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_v_posteriors_indptr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        }
      }
      __pyx_pybuffernd_posteriors_indptr.diminfo[0].strides = __pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_posteriors_indptr.diminfo[0].shape = __pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 233, __pyx_L1_error)
    }
    __pyx_t_17 = 0;
    __pyx_v_posteriors_indptr = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "_emirge_amplicon.pyx":225
 *     cdef np.ndarray[np.int32_t, ndim=1] posteriors_indptr
 * 
 *     if not initial_iteration:             # <<<<<<<<<<<<<<
 *         convert_t0 = time()
 *         em.posteriors[-2] = em.posteriors[-2].tocsr()
 */
    goto __pyx_L3;
  }

  /* "_emirge_amplicon.pyx":235
 *         posteriors_indptr = posteriors.indptr
 *     else:
 *         posteriors = None             # <<<<<<<<<<<<<<
 * 
 *     t_check = time()                    # DEBUG
 */
  /*else*/ {
    __Pyx_INCREF(Py_None);
    __pyx_v_posteriors = Py_None;
  }
  __pyx_L3:;

  /* "_emirge_amplicon.pyx":237
 *         posteriors = None
 * 
 *     t_check = time()                    # DEBUG             # <<<<<<<<<<<<<<
 *     cdef list probN      = em.probN       # list of numpy arrays.  At this point, only None values will be due to just-culled sequences.
 * 
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_t_check = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":238
 * 
 *     t_check = time()                    # DEBUG
 *     cdef list probN      = em.probN       # list of numpy arrays.  At this point, only None values will be due to just-culled sequences.             # <<<<<<<<<<<<<<
 * 
 *     # for bamfile_data
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (!(likely(PyList_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 238, __pyx_L1_error)
  __pyx_v_probN = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":263
 *     cdef np.ndarray[np.float_t, ndim=2] probN_single  # an individual probN numpy matrix.
 *     # cdef np.ndarray[np.uint8_t, ndim=1] new_read      # see below
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_seen = em.reads_seen      # ...in previous rounds             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_seen_this_round = np.zeros_like(reads_seen)      # see below
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads_seen); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 263, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 263, __pyx_L1_error)
  __pyx_t_18 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_reads_seen = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 263, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads_seen.diminfo[0].strides = __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads_seen.diminfo[0].shape = __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_18 = 0;
  __pyx_v_reads_seen = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":264
 *     # cdef np.ndarray[np.uint8_t, ndim=1] new_read      # see below
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_seen = em.reads_seen      # ...in previous rounds
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_seen_this_round = np.zeros_like(reads_seen)      # see below             # <<<<<<<<<<<<<<
 * 
 *     cdef np.ndarray[np.uint8_t, ndim=1] dead_seqs # these sequences have been removed just prior in reset_probN
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_reads_seen)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 264, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, ((PyObject *)__pyx_v_reads_seen)};
      __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 264, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, ((PyObject *)__pyx_v_reads_seen)};
      __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 264, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 264, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); __pyx_t_9 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_reads_seen));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_reads_seen));
      PyTuple_SET_ITEM(__pyx_t_1, 0+1, ((PyObject *)__pyx_v_reads_seen));
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 264, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 264, __pyx_L1_error)
  __pyx_t_19 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_reads_seen_this_round = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 264, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads_seen_this_round.diminfo[0].strides = __pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads_seen_this_round.diminfo[0].shape = __pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_19 = 0;
  __pyx_v_reads_seen_this_round = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":268
 *     cdef np.ndarray[np.uint8_t, ndim=1] dead_seqs # these sequences have been removed just prior in reset_probN
 *     # dead_seqs = np.array([1 if p is None else 0 for p in em.probN], dtype=np.uint8)  # doesn't compile?
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)  # this lookup faster than list lookup in main loop             # <<<<<<<<<<<<<<
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_20 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_20); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_uint8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 268, __pyx_L1_error)
  __pyx_t_21 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer, (PyObject*)__pyx_v_dead_seqs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
      }
    }
    __pyx_pybuffernd_dead_seqs.diminfo[0].strides = __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dead_seqs.diminfo[0].shape = __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 268, __pyx_L1_error)
  }
  __pyx_t_21 = 0;
  __pyx_v_dead_seqs = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "_emirge_amplicon.pyx":269
 *     # dead_seqs = np.array([1 if p is None else 0 for p in em.probN], dtype=np.uint8)  # doesn't compile?
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)  # this lookup faster than list lookup in main loop
 *     for seq_i in range(len(em.probN)):             # <<<<<<<<<<<<<<
 *         if em.probN[seq_i] is None:
 *             dead_seqs[seq_i] = 1
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_20 = PyObject_Length(__pyx_t_8); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 269, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_20; __pyx_t_22+=1) {
    __pyx_v_seq_i = __pyx_t_22;

    /* "_emirge_amplicon.pyx":270
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)  # this lookup faster than list lookup in main loop
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:             # <<<<<<<<<<<<<<
 *             dead_seqs[seq_i] = 1
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 270, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_8, __pyx_v_seq_i, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 270, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = (__pyx_t_7 == Py_None);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_23 = (__pyx_t_3 != 0);
    if (__pyx_t_23) {

      /* "_emirge_amplicon.pyx":271
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:
 *             dead_seqs[seq_i] = 1             # <<<<<<<<<<<<<<
 * 
 *     # print >> sys.stderr, "DEBUG: t_check 1: %s"%(timedelta(seconds = time() - t_check))
 */
      __pyx_t_24 = __pyx_v_seq_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_dead_seqs.diminfo[0].strides) = 1;

      /* "_emirge_amplicon.pyx":270
 *     dead_seqs = np.zeros(len(em.probN), dtype=np.uint8)  # this lookup faster than list lookup in main loop
 *     for seq_i in range(len(em.probN)):
 *         if em.probN[seq_i] is None:             # <<<<<<<<<<<<<<
 *             dead_seqs[seq_i] = 1
 * 
 */
    }
  }

  /* "_emirge_amplicon.pyx":275
 *     # print >> sys.stderr, "DEBUG: t_check 1: %s"%(timedelta(seconds = time() - t_check))
 * 
 *     loop_t0 = time()             # <<<<<<<<<<<<<<
 *     for alignedread_i in range(bamfile_data.shape[0]):
 *         #   0       1       2      3     4       5   # "efficient indexing only affects certain index operations, namely those with exactly ndim number of typed integer indices
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 275, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 275, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_loop_t0 = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":276
 * 
 *     loop_t0 = time()
 *     for alignedread_i in range(bamfile_data.shape[0]):             # <<<<<<<<<<<<<<
 *         #   0       1       2      3     4       5   # "efficient indexing only affects certain index operations, namely those with exactly ndim number of typed integer indices
 *         # seq_i, read_i, pair_i, rlen, pos, is_reverse = bamfile_data[alignedread_i]
 */
  __pyx_t_25 = (__pyx_v_bamfile_data->dimensions[0]);
  for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_25; __pyx_t_22+=1) {
    __pyx_v_alignedread_i = __pyx_t_22;

    /* "_emirge_amplicon.pyx":279
 *         #   0       1       2      3     4       5   # "efficient indexing only affects certain index operations, namely those with exactly ndim number of typed integer indices
 *         # seq_i, read_i, pair_i, rlen, pos, is_reverse = bamfile_data[alignedread_i]
 *         seq_i = bamfile_data[alignedread_i, 0]             # <<<<<<<<<<<<<<
 * 
 *         if dead_seqs[seq_i]:  # probN is None -- just culled.
 */
    __pyx_t_26 = __pyx_v_alignedread_i;
    __pyx_t_27 = 0;
    if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_seq_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":281
 *         seq_i = bamfile_data[alignedread_i, 0]
 * 
 *         if dead_seqs[seq_i]:  # probN is None -- just culled.             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    __pyx_t_28 = __pyx_v_seq_i;
    __pyx_t_23 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_dead_seqs.diminfo[0].strides)) != 0);
    if (__pyx_t_23) {

      /* "_emirge_amplicon.pyx":282
 * 
 *         if dead_seqs[seq_i]:  # probN is None -- just culled.
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         read_i = bamfile_data[alignedread_i, 1]
 */
      goto __pyx_L7_continue;

      /* "_emirge_amplicon.pyx":281
 *         seq_i = bamfile_data[alignedread_i, 0]
 * 
 *         if dead_seqs[seq_i]:  # probN is None -- just culled.             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "_emirge_amplicon.pyx":284
 *             continue
 * 
 *         read_i = bamfile_data[alignedread_i, 1]             # <<<<<<<<<<<<<<
 *         pair_i = bamfile_data[alignedread_i, 2]
 *         rlen = bamfile_data[alignedread_i, 3]
 */
    __pyx_t_29 = __pyx_v_alignedread_i;
    __pyx_t_30 = 1;
    if (__pyx_t_30 < 0) __pyx_t_30 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_read_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":285
 * 
 *         read_i = bamfile_data[alignedread_i, 1]
 *         pair_i = bamfile_data[alignedread_i, 2]             # <<<<<<<<<<<<<<
 *         rlen = bamfile_data[alignedread_i, 3]
 *         pos = bamfile_data[alignedread_i, 4]
 */
    __pyx_t_31 = __pyx_v_alignedread_i;
    __pyx_t_32 = 2;
    if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_pair_i = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_32, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":286
 *         read_i = bamfile_data[alignedread_i, 1]
 *         pair_i = bamfile_data[alignedread_i, 2]
 *         rlen = bamfile_data[alignedread_i, 3]             # <<<<<<<<<<<<<<
 *         pos = bamfile_data[alignedread_i, 4]
 *         is_reverse= bamfile_data[alignedread_i, 5]
 */
    __pyx_t_33 = __pyx_v_alignedread_i;
    __pyx_t_34 = 3;
    if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_rlen = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_33, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_34, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":287
 *         pair_i = bamfile_data[alignedread_i, 2]
 *         rlen = bamfile_data[alignedread_i, 3]
 *         pos = bamfile_data[alignedread_i, 4]             # <<<<<<<<<<<<<<
 *         is_reverse= bamfile_data[alignedread_i, 5]
 * 
 */
    __pyx_t_35 = __pyx_v_alignedread_i;
    __pyx_t_36 = 4;
    if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_pos = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_35, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_36, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":288
 *         rlen = bamfile_data[alignedread_i, 3]
 *         pos = bamfile_data[alignedread_i, 4]
 *         is_reverse= bamfile_data[alignedread_i, 5]             # <<<<<<<<<<<<<<
 * 
 *         reads_seen_this_round[read_i] = 1
 */
    __pyx_t_37 = __pyx_v_alignedread_i;
    __pyx_t_38 = 5;
    if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
    __pyx_v_is_reverse = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_37, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_38, __pyx_pybuffernd_bamfile_data.diminfo[1].strides));

    /* "_emirge_amplicon.pyx":290
 *         is_reverse= bamfile_data[alignedread_i, 5]
 * 
 *         reads_seen_this_round[read_i] = 1             # <<<<<<<<<<<<<<
 *         # find weight
 *         if initial_iteration:
 */
    __pyx_t_39 = __pyx_v_read_i;
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer.buf, __pyx_t_39, __pyx_pybuffernd_reads_seen_this_round.diminfo[0].strides) = 1;

    /* "_emirge_amplicon.pyx":292
 *         reads_seen_this_round[read_i] = 1
 *         # find weight
 *         if initial_iteration:             # <<<<<<<<<<<<<<
 *             weight = priors[seq_i]
 *         else:
 */
    __pyx_t_23 = (__pyx_v_initial_iteration != 0);
    if (__pyx_t_23) {

      /* "_emirge_amplicon.pyx":293
 *         # find weight
 *         if initial_iteration:
 *             weight = priors[seq_i]             # <<<<<<<<<<<<<<
 *         else:
 *             if reads_seen[read_i] == 0:
 */
      __pyx_t_40 = __pyx_v_seq_i;
      __pyx_v_weight = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_priors.rcbuffer->pybuffer.buf, __pyx_t_40, __pyx_pybuffernd_priors.diminfo[0].strides));

      /* "_emirge_amplicon.pyx":292
 *         reads_seen_this_round[read_i] = 1
 *         # find weight
 *         if initial_iteration:             # <<<<<<<<<<<<<<
 *             weight = priors[seq_i]
 *         else:
 */
      goto __pyx_L10;
    }

    /* "_emirge_amplicon.pyx":295
 *             weight = priors[seq_i]
 *         else:
 *             if reads_seen[read_i] == 0:             # <<<<<<<<<<<<<<
 *                 weight = priors[seq_i]
 *             else: # get weight from posteriors internal data structures
 */
    /*else*/ {
      __pyx_t_41 = __pyx_v_read_i;
      __pyx_t_23 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.buf, __pyx_t_41, __pyx_pybuffernd_reads_seen.diminfo[0].strides)) == 0) != 0);
      if (__pyx_t_23) {

        /* "_emirge_amplicon.pyx":296
 *         else:
 *             if reads_seen[read_i] == 0:
 *                 weight = priors[seq_i]             # <<<<<<<<<<<<<<
 *             else: # get weight from posteriors internal data structures
 *                 # here: no bounds checking, try to do as much in cython as possible
 */
        __pyx_t_42 = __pyx_v_seq_i;
        __pyx_v_weight = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_priors.rcbuffer->pybuffer.buf, __pyx_t_42, __pyx_pybuffernd_priors.diminfo[0].strides));

        /* "_emirge_amplicon.pyx":295
 *             weight = priors[seq_i]
 *         else:
 *             if reads_seen[read_i] == 0:             # <<<<<<<<<<<<<<
 *                 weight = priors[seq_i]
 *             else: # get weight from posteriors internal data structures
 */
        goto __pyx_L11;
      }

      /* "_emirge_amplicon.pyx":301
 *                 # weight = posteriors[seq_i, read_i]    # simple way to do this, but slower
 * 
 *                 lo = posteriors_indptr[seq_i]             # <<<<<<<<<<<<<<
 *                 hi   = posteriors_indptr[seq_i+1]
 *                 # binary search (indices are sorted)
 */
      /*else*/ {
        __pyx_t_43 = __pyx_v_seq_i;
        __pyx_t_7 = __Pyx_PyInt_From_npy_int32((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer.buf, __pyx_t_43, __pyx_pybuffernd_posteriors_indptr.diminfo[0].strides))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 301, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_XDECREF_SET(__pyx_v_lo, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "_emirge_amplicon.pyx":302
 * 
 *                 lo = posteriors_indptr[seq_i]
 *                 hi   = posteriors_indptr[seq_i+1]             # <<<<<<<<<<<<<<
 *                 # binary search (indices are sorted)
 *                 weight = 0.0  # default value if read_i not found
 */
        __pyx_t_44 = (__pyx_v_seq_i + 1);
        if (__pyx_t_44 < 0) __pyx_t_44 += __pyx_pybuffernd_posteriors_indptr.diminfo[0].shape;
        __pyx_v_hi = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer.buf, __pyx_t_44, __pyx_pybuffernd_posteriors_indptr.diminfo[0].strides));

        /* "_emirge_amplicon.pyx":304
 *                 hi   = posteriors_indptr[seq_i+1]
 *                 # binary search (indices are sorted)
 *                 weight = 0.0  # default value if read_i not found             # <<<<<<<<<<<<<<
 *                 while lo < hi:
 *                     mid = (lo+hi)//2
 */
        __pyx_v_weight = 0.0;

        /* "_emirge_amplicon.pyx":305
 *                 # binary search (indices are sorted)
 *                 weight = 0.0  # default value if read_i not found
 *                 while lo < hi:             # <<<<<<<<<<<<<<
 *                     mid = (lo+hi)//2
 *                     midval = posteriors_indices[mid]
 */
        while (1) {
          __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_hi); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = PyObject_RichCompare(__pyx_v_lo, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_23 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_23 < 0)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (!__pyx_t_23) break;

          /* "_emirge_amplicon.pyx":306
 *                 weight = 0.0  # default value if read_i not found
 *                 while lo < hi:
 *                     mid = (lo+hi)//2             # <<<<<<<<<<<<<<
 *                     midval = posteriors_indices[mid]
 *                     if midval < read_i:
 */
          __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_hi); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = PyNumber_Add(__pyx_v_lo, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 306, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_7, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 306, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_v_mid = __pyx_t_12;

          /* "_emirge_amplicon.pyx":307
 *                 while lo < hi:
 *                     mid = (lo+hi)//2
 *                     midval = posteriors_indices[mid]             # <<<<<<<<<<<<<<
 *                     if midval < read_i:
 *                         lo = mid + 1
 */
          __pyx_t_45 = __pyx_v_mid;
          if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_pybuffernd_posteriors_indices.diminfo[0].shape;
          __pyx_v_midval = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer.buf, __pyx_t_45, __pyx_pybuffernd_posteriors_indices.diminfo[0].strides));

          /* "_emirge_amplicon.pyx":308
 *                     mid = (lo+hi)//2
 *                     midval = posteriors_indices[mid]
 *                     if midval < read_i:             # <<<<<<<<<<<<<<
 *                         lo = mid + 1
 *                     elif midval > read_i:
 */
          __pyx_t_23 = ((__pyx_v_midval < __pyx_v_read_i) != 0);
          if (__pyx_t_23) {

            /* "_emirge_amplicon.pyx":309
 *                     midval = posteriors_indices[mid]
 *                     if midval < read_i:
 *                         lo = mid + 1             # <<<<<<<<<<<<<<
 *                     elif midval > read_i:
 *                         hi = mid
 */
            __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_v_mid + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 309, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF_SET(__pyx_v_lo, __pyx_t_8);
            __pyx_t_8 = 0;

            /* "_emirge_amplicon.pyx":308
 *                     mid = (lo+hi)//2
 *                     midval = posteriors_indices[mid]
 *                     if midval < read_i:             # <<<<<<<<<<<<<<
 *                         lo = mid + 1
 *                     elif midval > read_i:
 */
            goto __pyx_L14;
          }

          /* "_emirge_amplicon.pyx":310
 *                     if midval < read_i:
 *                         lo = mid + 1
 *                     elif midval > read_i:             # <<<<<<<<<<<<<<
 *                         hi = mid
 *                     else: # found it
 */
          __pyx_t_23 = ((__pyx_v_midval > __pyx_v_read_i) != 0);
          if (__pyx_t_23) {

            /* "_emirge_amplicon.pyx":311
 *                         lo = mid + 1
 *                     elif midval > read_i:
 *                         hi = mid             # <<<<<<<<<<<<<<
 *                     else: # found it
 *                         weight = posteriors_data[mid]
 */
            __pyx_v_hi = __pyx_v_mid;

            /* "_emirge_amplicon.pyx":310
 *                     if midval < read_i:
 *                         lo = mid + 1
 *                     elif midval > read_i:             # <<<<<<<<<<<<<<
 *                         hi = mid
 *                     else: # found it
 */
            goto __pyx_L14;
          }

          /* "_emirge_amplicon.pyx":313
 *                         hi = mid
 *                     else: # found it
 *                         weight = posteriors_data[mid]             # <<<<<<<<<<<<<<
 *                         break
 *                 # assert weight == posteriors[seq_i, read_i], "%s vs %s"%(weight, posteriors[seq_i, read_i])  # DEBUG.  Make sure I'm doing this right, since no error checking otherwise
 */
          /*else*/ {
            __pyx_t_46 = __pyx_v_mid;
            if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_pybuffernd_posteriors_data.diminfo[0].shape;
            __pyx_v_weight = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf, __pyx_t_46, __pyx_pybuffernd_posteriors_data.diminfo[0].strides));

            /* "_emirge_amplicon.pyx":314
 *                     else: # found it
 *                         weight = posteriors_data[mid]
 *                         break             # <<<<<<<<<<<<<<
 *                 # assert weight == posteriors[seq_i, read_i], "%s vs %s"%(weight, posteriors[seq_i, read_i])  # DEBUG.  Make sure I'm doing this right, since no error checking otherwise
 * 
 */
            goto __pyx_L13_break;
          }
          __pyx_L14:;
        }
        __pyx_L13_break:;
      }
      __pyx_L11:;
    }
    __pyx_L10:;

    /* "_emirge_amplicon.pyx":317
 *                 # assert weight == posteriors[seq_i, read_i], "%s vs %s"%(weight, posteriors[seq_i, read_i])  # DEBUG.  Make sure I'm doing this right, since no error checking otherwise
 * 
 *         probN_single = probN[seq_i]             # <<<<<<<<<<<<<<
 * 
 *         if is_reverse:
 */
    if (unlikely(__pyx_v_probN == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 317, __pyx_L1_error)
    }
    if (!(likely(((PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i)) == Py_None) || likely(__Pyx_TypeTest(PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i), __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 317, __pyx_L1_error)
    __pyx_t_8 = PyList_GET_ITEM(__pyx_v_probN, __pyx_v_seq_i);
    __Pyx_INCREF(__pyx_t_8);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_8), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)__pyx_v_probN_single, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        }
      }
      __pyx_pybuffernd_probN_single.diminfo[0].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_probN_single.diminfo[0].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_probN_single.diminfo[1].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_probN_single.diminfo[1].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 317, __pyx_L1_error)
    }
    __Pyx_XDECREF_SET(__pyx_v_probN_single, ((PyArrayObject *)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "_emirge_amplicon.pyx":319
 *         probN_single = probN[seq_i]
 * 
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             # manually inline reverse complement loop here.  It's redundant, but it's all in the name of speed.
 *             for i in range(rlen):
 */
    __pyx_t_23 = (__pyx_v_is_reverse != 0);
    if (__pyx_t_23) {

      /* "_emirge_amplicon.pyx":321
 *         if is_reverse:
 *             # manually inline reverse complement loop here.  It's redundant, but it's all in the name of speed.
 *             for i in range(rlen):             # <<<<<<<<<<<<<<
 *                 ii = rlen-1-i # the index to the base given that this seq is reversed
 *                 for j in range(4):
 */
      __pyx_t_47 = __pyx_v_rlen;
      for (__pyx_t_48 = 0; __pyx_t_48 < __pyx_t_47; __pyx_t_48+=1) {
        __pyx_v_i = __pyx_t_48;

        /* "_emirge_amplicon.pyx":322
 *             # manually inline reverse complement loop here.  It's redundant, but it's all in the name of speed.
 *             for i in range(rlen):
 *                 ii = rlen-1-i # the index to the base given that this seq is reversed             # <<<<<<<<<<<<<<
 *                 for j in range(4):
 *                     if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, add (1-P) * weight
 */
        __pyx_v_ii = ((__pyx_v_rlen - 1) - __pyx_v_i);

        /* "_emirge_amplicon.pyx":323
 *             for i in range(rlen):
 *                 ii = rlen-1-i # the index to the base given that this seq is reversed
 *                 for j in range(4):             # <<<<<<<<<<<<<<
 *                     if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, add (1-P) * weight
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * weight )
 */
        for (__pyx_t_49 = 0; __pyx_t_49 < 4; __pyx_t_49+=1) {
          __pyx_v_j = __pyx_t_49;

          /* "_emirge_amplicon.pyx":324
 *                 ii = rlen-1-i # the index to the base given that this seq is reversed
 *                 for j in range(4):
 *                     if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, add (1-P) * weight             # <<<<<<<<<<<<<<
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 */
          __pyx_t_50 = __pyx_v_read_i;
          __pyx_t_51 = __pyx_v_pair_i;
          __pyx_t_52 = __pyx_v_ii;
          __pyx_t_23 = ((__pyx_f_16_emirge_amplicon_complement_numeric_base((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf, __pyx_t_50, __pyx_pybuffernd_reads.diminfo[0].strides, __pyx_t_51, __pyx_pybuffernd_reads.diminfo[1].strides, __pyx_t_52, __pyx_pybuffernd_reads.diminfo[2].strides))) == __pyx_v_j) != 0);
          if (__pyx_t_23) {

            /* "_emirge_amplicon.pyx":325
 *                 for j in range(4):
 *                     if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, add (1-P) * weight
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * weight )             # <<<<<<<<<<<<<<
 *                     else:                       # this is not the called base, so add P/3 * weight
 *                         probN_single[pos + i, j] += ( qual2p_div_3[quals[read_i, pair_i, ii]] * weight )
 */
            __pyx_t_53 = __pyx_v_read_i;
            __pyx_t_54 = __pyx_v_pair_i;
            __pyx_t_55 = __pyx_v_ii;
            __pyx_t_56 = (__pyx_v_pos + __pyx_v_i);
            __pyx_t_57 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_56, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_57, __pyx_pybuffernd_probN_single.diminfo[1].strides) += ((qual2one_minus_p[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_53, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_54, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_55, __pyx_pybuffernd_quals.diminfo[2].strides))]) * __pyx_v_weight);

            /* "_emirge_amplicon.pyx":324
 *                 ii = rlen-1-i # the index to the base given that this seq is reversed
 *                 for j in range(4):
 *                     if complement_numeric_base(reads[read_i, pair_i, ii]) == j:   # this is called base, add (1-P) * weight             # <<<<<<<<<<<<<<
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 */
            goto __pyx_L20;
          }

          /* "_emirge_amplicon.pyx":327
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, ii]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 *                         probN_single[pos + i, j] += ( qual2p_div_3[quals[read_i, pair_i, ii]] * weight )             # <<<<<<<<<<<<<<
 * 
 *         else: # not reverse
 */
          /*else*/ {
            __pyx_t_58 = __pyx_v_read_i;
            __pyx_t_59 = __pyx_v_pair_i;
            __pyx_t_60 = __pyx_v_ii;
            __pyx_t_61 = (__pyx_v_pos + __pyx_v_i);
            __pyx_t_62 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_61, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_62, __pyx_pybuffernd_probN_single.diminfo[1].strides) += ((qual2p_div_3[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_58, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_59, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_60, __pyx_pybuffernd_quals.diminfo[2].strides))]) * __pyx_v_weight);
          }
          __pyx_L20:;
        }
      }

      /* "_emirge_amplicon.pyx":319
 *         probN_single = probN[seq_i]
 * 
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             # manually inline reverse complement loop here.  It's redundant, but it's all in the name of speed.
 *             for i in range(rlen):
 */
      goto __pyx_L15;
    }

    /* "_emirge_amplicon.pyx":330
 * 
 *         else: # not reverse
 *             for i in range(rlen):             # <<<<<<<<<<<<<<
 *                 for j in range(4):
 *                     if reads[read_i, pair_i, i] == j:   # this is called base, add (1-P) * weight
 */
    /*else*/ {
      __pyx_t_47 = __pyx_v_rlen;
      for (__pyx_t_48 = 0; __pyx_t_48 < __pyx_t_47; __pyx_t_48+=1) {
        __pyx_v_i = __pyx_t_48;

        /* "_emirge_amplicon.pyx":331
 *         else: # not reverse
 *             for i in range(rlen):
 *                 for j in range(4):             # <<<<<<<<<<<<<<
 *                     if reads[read_i, pair_i, i] == j:   # this is called base, add (1-P) * weight
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, i]] * weight )
 */
        for (__pyx_t_49 = 0; __pyx_t_49 < 4; __pyx_t_49+=1) {
          __pyx_v_j = __pyx_t_49;

          /* "_emirge_amplicon.pyx":332
 *             for i in range(rlen):
 *                 for j in range(4):
 *                     if reads[read_i, pair_i, i] == j:   # this is called base, add (1-P) * weight             # <<<<<<<<<<<<<<
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, i]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 */
          __pyx_t_63 = __pyx_v_read_i;
          __pyx_t_64 = __pyx_v_pair_i;
          __pyx_t_65 = __pyx_v_i;
          __pyx_t_23 = (((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf, __pyx_t_63, __pyx_pybuffernd_reads.diminfo[0].strides, __pyx_t_64, __pyx_pybuffernd_reads.diminfo[1].strides, __pyx_t_65, __pyx_pybuffernd_reads.diminfo[2].strides)) == __pyx_v_j) != 0);
          if (__pyx_t_23) {

            /* "_emirge_amplicon.pyx":333
 *                 for j in range(4):
 *                     if reads[read_i, pair_i, i] == j:   # this is called base, add (1-P) * weight
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, i]] * weight )             # <<<<<<<<<<<<<<
 *                     else:                       # this is not the called base, so add P/3 * weight
 *                         probN_single[pos + i, j] += ( qual2p_div_3[quals[read_i, pair_i, i]] * weight )
 */
            __pyx_t_66 = __pyx_v_read_i;
            __pyx_t_67 = __pyx_v_pair_i;
            __pyx_t_68 = __pyx_v_i;
            __pyx_t_69 = (__pyx_v_pos + __pyx_v_i);
            __pyx_t_70 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_69, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_70, __pyx_pybuffernd_probN_single.diminfo[1].strides) += ((qual2one_minus_p[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_66, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_67, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_68, __pyx_pybuffernd_quals.diminfo[2].strides))]) * __pyx_v_weight);

            /* "_emirge_amplicon.pyx":332
 *             for i in range(rlen):
 *                 for j in range(4):
 *                     if reads[read_i, pair_i, i] == j:   # this is called base, add (1-P) * weight             # <<<<<<<<<<<<<<
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, i]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 */
            goto __pyx_L25;
          }

          /* "_emirge_amplicon.pyx":335
 *                         probN_single[pos + i, j] += ( qual2one_minus_p[quals[read_i, pair_i, i]] * weight )
 *                     else:                       # this is not the called base, so add P/3 * weight
 *                         probN_single[pos + i, j] += ( qual2p_div_3[quals[read_i, pair_i, i]] * weight )             # <<<<<<<<<<<<<<
 * 
 *     td = timedelta(seconds = time()-loop_t0)
 */
          /*else*/ {
            __pyx_t_71 = __pyx_v_read_i;
            __pyx_t_72 = __pyx_v_pair_i;
            __pyx_t_73 = __pyx_v_i;
            __pyx_t_74 = (__pyx_v_pos + __pyx_v_i);
            __pyx_t_75 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_74, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_75, __pyx_pybuffernd_probN_single.diminfo[1].strides) += ((qual2p_div_3[(*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_71, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_72, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_73, __pyx_pybuffernd_quals.diminfo[2].strides))]) * __pyx_v_weight);
          }
          __pyx_L25:;
        }
      }
    }
    __pyx_L15:;
    __pyx_L7_continue:;
  }

  /* "_emirge_amplicon.pyx":337
 *                         probN_single[pos + i, j] += ( qual2p_div_3[quals[read_i, pair_i, i]] * weight )
 * 
 *     td = timedelta(seconds = time()-loop_t0)             # <<<<<<<<<<<<<<
 *     # print >> sys.stderr, "DEBUG: iteration %02d _calc_probN time per 1000 bam entries: %.2e seconds"%(em.iteration_i, (((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)) / alignedread_i) * 1000.0) # DEBUG
 *     # print >> sys.stderr, "DEBUG: total loop time (%s bam entries): %s"%(alignedread_i, td)
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_timedelta); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_9) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_v_loop_t0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_seconds, __pyx_t_2) < 0) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_td = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":341
 *     # print >> sys.stderr, "DEBUG: total loop time (%s bam entries): %s"%(alignedread_i, td)
 * 
 *     t_check = time()                    # DEBUG             # <<<<<<<<<<<<<<
 * 
 *     # at this point, probN contains sums.
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_8) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_t_check, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":352
 *     cdef char* seq
 *     cdef unsigned short reference_base
 *     cdef double one_minus_p = 1.0 - em.DEFAULT_ERROR             # <<<<<<<<<<<<<<
 *     cdef double p_div_3     = em.DEFAULT_ERROR / 3.0
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_DEFAULT_ERROR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyFloat_SubtractCObj(__pyx_float_1_0, __pyx_t_2, 1.0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_76 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_76 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_one_minus_p = __pyx_t_76;

  /* "_emirge_amplicon.pyx":353
 *     cdef unsigned short reference_base
 *     cdef double one_minus_p = 1.0 - em.DEFAULT_ERROR
 *     cdef double p_div_3     = em.DEFAULT_ERROR / 3.0             # <<<<<<<<<<<<<<
 * 
 *     sequence_i2sequence_name_array = np.array(em.sequence_i2sequence_name)  # faster slicing. can't cdef string arrays yet.
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_DEFAULT_ERROR); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_PyFloat_DivideObjC(__pyx_t_7, __pyx_float_3_0, 3.0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_76 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_76 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_p_div_3 = __pyx_t_76;

  /* "_emirge_amplicon.pyx":355
 *     cdef double p_div_3     = em.DEFAULT_ERROR / 3.0
 * 
 *     sequence_i2sequence_name_array = np.array(em.sequence_i2sequence_name)  # faster slicing. can't cdef string arrays yet.             # <<<<<<<<<<<<<<
 * 
 *     for seq_i, probN_single in enumerate(em.probN):
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_sequence_i2sequence_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_7};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_7};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 355, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_sequence_i2sequence_name_array = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":357
 *     sequence_i2sequence_name_array = np.array(em.sequence_i2sequence_name)  # faster slicing. can't cdef string arrays yet.
 * 
 *     for seq_i, probN_single in enumerate(em.probN):             # <<<<<<<<<<<<<<
 *         if probN_single is None:  # means this sequence no longer present
 *             em.unmapped_bases[seq_i] = None
 */
  __pyx_t_22 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_8 = __pyx_t_2; __Pyx_INCREF(__pyx_t_8); __pyx_t_20 = 0;
    __pyx_t_77 = NULL;
  } else {
    __pyx_t_20 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_77 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_77)) __PYX_ERR(0, 357, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_77)) {
      if (likely(PyList_CheckExact(__pyx_t_8))) {
        if (__pyx_t_20 >= PyList_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_20); __Pyx_INCREF(__pyx_t_2); __pyx_t_20++; if (unlikely(0 < 0)) __PYX_ERR(0, 357, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_20); __pyx_t_20++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_20 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_20); __Pyx_INCREF(__pyx_t_2); __pyx_t_20++; if (unlikely(0 < 0)) __PYX_ERR(0, 357, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_20); __pyx_t_20++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_77(__pyx_t_8);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 357, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 357, __pyx_L1_error)
    __pyx_t_78 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)__pyx_t_78, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer, (PyObject*)__pyx_v_probN_single, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_probN_single.diminfo[0].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_probN_single.diminfo[0].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_probN_single.diminfo[1].strides = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_probN_single.diminfo[1].shape = __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 357, __pyx_L1_error)
    }
    __pyx_t_78 = 0;
    __Pyx_XDECREF_SET(__pyx_v_probN_single, ((PyArrayObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_v_seq_i = __pyx_t_22;
    __pyx_t_22 = (__pyx_t_22 + 1);

    /* "_emirge_amplicon.pyx":358
 * 
 *     for seq_i, probN_single in enumerate(em.probN):
 *         if probN_single is None:  # means this sequence no longer present             # <<<<<<<<<<<<<<
 *             em.unmapped_bases[seq_i] = None
 *             continue
 */
    __pyx_t_23 = (((PyObject *)__pyx_v_probN_single) == Py_None);
    __pyx_t_3 = (__pyx_t_23 != 0);
    if (__pyx_t_3) {

      /* "_emirge_amplicon.pyx":359
 *     for seq_i, probN_single in enumerate(em.probN):
 *         if probN_single is None:  # means this sequence no longer present
 *             em.unmapped_bases[seq_i] = None             # <<<<<<<<<<<<<<
 *             continue
 *         # get sequence for nonmapped bases.  Just get for all, even though only need for ones with nonmapped.
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_unmapped_bases); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(__Pyx_SetItemInt(__pyx_t_2, __pyx_v_seq_i, Py_None, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0) < 0)) __PYX_ERR(0, 359, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "_emirge_amplicon.pyx":360
 *         if probN_single is None:  # means this sequence no longer present
 *             em.unmapped_bases[seq_i] = None
 *             continue             # <<<<<<<<<<<<<<
 *         # get sequence for nonmapped bases.  Just get for all, even though only need for ones with nonmapped.
 *         # not sure if this is particularly slow.
 */
      goto __pyx_L26_continue;

      /* "_emirge_amplicon.pyx":358
 * 
 *     for seq_i, probN_single in enumerate(em.probN):
 *         if probN_single is None:  # means this sequence no longer present             # <<<<<<<<<<<<<<
 *             em.unmapped_bases[seq_i] = None
 *             continue
 */
    }

    /* "_emirge_amplicon.pyx":363
 *         # get sequence for nonmapped bases.  Just get for all, even though only need for ones with nonmapped.
 *         # not sure if this is particularly slow.
 *         py_seq = em.fastafile.fetch(str(sequence_i2sequence_name_array[seq_i]))             # <<<<<<<<<<<<<<
 *         seq = py_seq  # necessary workaround for strings in Cython
 *         seq_bases = seq_alpha2int(seq, len(py_seq))
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_fastafile); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_fetch); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_sequence_i2sequence_name_array, __pyx_v_seq_i, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_9};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_9};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      {
        __pyx_t_79 = PyTuple_New(1+1); if (unlikely(!__pyx_t_79)) __PYX_ERR(0, 363, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_79);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_79, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_79, 0+1, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_79, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_79); __pyx_t_79 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_py_seq, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "_emirge_amplicon.pyx":364
 *         # not sure if this is particularly slow.
 *         py_seq = em.fastafile.fetch(str(sequence_i2sequence_name_array[seq_i]))
 *         seq = py_seq  # necessary workaround for strings in Cython             # <<<<<<<<<<<<<<
 *         seq_bases = seq_alpha2int(seq, len(py_seq))
 * 
 */
    __pyx_t_80 = __Pyx_PyObject_AsString(__pyx_v_py_seq); if (unlikely((!__pyx_t_80) && PyErr_Occurred())) __PYX_ERR(0, 364, __pyx_L1_error)
    __pyx_v_seq = __pyx_t_80;

    /* "_emirge_amplicon.pyx":365
 *         py_seq = em.fastafile.fetch(str(sequence_i2sequence_name_array[seq_i]))
 *         seq = py_seq  # necessary workaround for strings in Cython
 *         seq_bases = seq_alpha2int(seq, len(py_seq))             # <<<<<<<<<<<<<<
 * 
 *         unmapped_bases = np.zeros(probN_single.shape[0], dtype=np.uint8)
 */
    __pyx_t_81 = PyObject_Length(__pyx_v_py_seq); if (unlikely(__pyx_t_81 == -1)) __PYX_ERR(0, 365, __pyx_L1_error)
    __pyx_t_2 = ((PyObject *)__pyx_f_16_emirge_amplicon_seq_alpha2int(__pyx_v_seq, __pyx_t_81)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seq_bases.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seq_bases.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_seq_bases.rcbuffer->pybuffer, (PyObject*)__pyx_v_seq_bases, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        }
      }
      __pyx_pybuffernd_seq_bases.diminfo[0].strides = __pyx_pybuffernd_seq_bases.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_seq_bases.diminfo[0].shape = __pyx_pybuffernd_seq_bases.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 365, __pyx_L1_error)
    }
    __Pyx_XDECREF_SET(__pyx_v_seq_bases, ((PyArrayObject *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "_emirge_amplicon.pyx":367
 *         seq_bases = seq_alpha2int(seq, len(py_seq))
 * 
 *         unmapped_bases = np.zeros(probN_single.shape[0], dtype=np.uint8)             # <<<<<<<<<<<<<<
 *         # sum probs for each base, divide cells by this sum for probs.
 *         # only divide cells with at least one base mapped.
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_Py_intptr_t((__pyx_v_probN_single->dimensions[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_79 = PyTuple_New(1); if (unlikely(!__pyx_t_79)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_79);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_79, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_uint8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_79, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_79); __pyx_t_79 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 367, __pyx_L1_error)
    __pyx_t_82 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer);
      __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer, (PyObject*)__pyx_t_82, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_12 < 0)) {
        PyErr_Fetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer, (PyObject*)__pyx_v_unmapped_bases, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_unmapped_bases.diminfo[0].strides = __pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_unmapped_bases.diminfo[0].shape = __pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 367, __pyx_L1_error)
    }
    __pyx_t_82 = 0;
    __Pyx_XDECREF_SET(__pyx_v_unmapped_bases, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "_emirge_amplicon.pyx":371
 *         # only divide cells with at least one base mapped.
 * 
 *         for i in range(probN_single.shape[0]):             # <<<<<<<<<<<<<<
 *             base_sum = 0
 *             for j in range(4):
 */
    __pyx_t_25 = (__pyx_v_probN_single->dimensions[0]);
    for (__pyx_t_47 = 0; __pyx_t_47 < __pyx_t_25; __pyx_t_47+=1) {
      __pyx_v_i = __pyx_t_47;

      /* "_emirge_amplicon.pyx":372
 * 
 *         for i in range(probN_single.shape[0]):
 *             base_sum = 0             # <<<<<<<<<<<<<<
 *             for j in range(4):
 *                 base_sum = base_sum + probN_single[i, j]
 */
      __pyx_v_base_sum = 0.0;

      /* "_emirge_amplicon.pyx":373
 *         for i in range(probN_single.shape[0]):
 *             base_sum = 0
 *             for j in range(4):             # <<<<<<<<<<<<<<
 *                 base_sum = base_sum + probN_single[i, j]
 *             # if no mappings, give 1. - em.DEFAULT_ERROR to existing reference base and em.DEFAULT_ERROR / 3 to everyone else.
 */
      for (__pyx_t_48 = 0; __pyx_t_48 < 4; __pyx_t_48+=1) {
        __pyx_v_j = __pyx_t_48;

        /* "_emirge_amplicon.pyx":374
 *             base_sum = 0
 *             for j in range(4):
 *                 base_sum = base_sum + probN_single[i, j]             # <<<<<<<<<<<<<<
 *             # if no mappings, give 1. - em.DEFAULT_ERROR to existing reference base and em.DEFAULT_ERROR / 3 to everyone else.
 *             if base_sum == 0:
 */
        __pyx_t_83 = __pyx_v_i;
        __pyx_t_84 = __pyx_v_j;
        __pyx_v_base_sum = (__pyx_v_base_sum + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_83, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_84, __pyx_pybuffernd_probN_single.diminfo[1].strides)));
      }

      /* "_emirge_amplicon.pyx":376
 *                 base_sum = base_sum + probN_single[i, j]
 *             # if no mappings, give 1. - em.DEFAULT_ERROR to existing reference base and em.DEFAULT_ERROR / 3 to everyone else.
 *             if base_sum == 0:             # <<<<<<<<<<<<<<
 *                 unmapped_bases[i] = 1
 *                 reference_base = seq_bases[i]
 */
      __pyx_t_3 = ((__pyx_v_base_sum == 0.0) != 0);
      if (__pyx_t_3) {

        /* "_emirge_amplicon.pyx":377
 *             # if no mappings, give 1. - em.DEFAULT_ERROR to existing reference base and em.DEFAULT_ERROR / 3 to everyone else.
 *             if base_sum == 0:
 *                 unmapped_bases[i] = 1             # <<<<<<<<<<<<<<
 *                 reference_base = seq_bases[i]
 *                 for j in range(4):
 */
        __pyx_t_85 = __pyx_v_i;
        *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer.buf, __pyx_t_85, __pyx_pybuffernd_unmapped_bases.diminfo[0].strides) = 1;

        /* "_emirge_amplicon.pyx":378
 *             if base_sum == 0:
 *                 unmapped_bases[i] = 1
 *                 reference_base = seq_bases[i]             # <<<<<<<<<<<<<<
 *                 for j in range(4):
 *                     if j == reference_base:
 */
        __pyx_t_86 = __pyx_v_i;
        __pyx_v_reference_base = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_seq_bases.rcbuffer->pybuffer.buf, __pyx_t_86, __pyx_pybuffernd_seq_bases.diminfo[0].strides));

        /* "_emirge_amplicon.pyx":379
 *                 unmapped_bases[i] = 1
 *                 reference_base = seq_bases[i]
 *                 for j in range(4):             # <<<<<<<<<<<<<<
 *                     if j == reference_base:
 *                         probN_single[i, j] = one_minus_p
 */
        for (__pyx_t_48 = 0; __pyx_t_48 < 4; __pyx_t_48+=1) {
          __pyx_v_j = __pyx_t_48;

          /* "_emirge_amplicon.pyx":380
 *                 reference_base = seq_bases[i]
 *                 for j in range(4):
 *                     if j == reference_base:             # <<<<<<<<<<<<<<
 *                         probN_single[i, j] = one_minus_p
 *                     else:
 */
          __pyx_t_3 = ((__pyx_v_j == __pyx_v_reference_base) != 0);
          if (__pyx_t_3) {

            /* "_emirge_amplicon.pyx":381
 *                 for j in range(4):
 *                     if j == reference_base:
 *                         probN_single[i, j] = one_minus_p             # <<<<<<<<<<<<<<
 *                     else:
 *                         probN_single[i, j] = p_div_3
 */
            __pyx_t_87 = __pyx_v_i;
            __pyx_t_88 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_87, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_88, __pyx_pybuffernd_probN_single.diminfo[1].strides) = __pyx_v_one_minus_p;

            /* "_emirge_amplicon.pyx":380
 *                 reference_base = seq_bases[i]
 *                 for j in range(4):
 *                     if j == reference_base:             # <<<<<<<<<<<<<<
 *                         probN_single[i, j] = one_minus_p
 *                     else:
 */
            goto __pyx_L36;
          }

          /* "_emirge_amplicon.pyx":383
 *                         probN_single[i, j] = one_minus_p
 *                     else:
 *                         probN_single[i, j] = p_div_3             # <<<<<<<<<<<<<<
 *             else: # has mappings.  adjust probs.
 *                 for j in range(4):
 */
          /*else*/ {
            __pyx_t_89 = __pyx_v_i;
            __pyx_t_90 = __pyx_v_j;
            *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_89, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_90, __pyx_pybuffernd_probN_single.diminfo[1].strides) = __pyx_v_p_div_3;
          }
          __pyx_L36:;
        }

        /* "_emirge_amplicon.pyx":376
 *                 base_sum = base_sum + probN_single[i, j]
 *             # if no mappings, give 1. - em.DEFAULT_ERROR to existing reference base and em.DEFAULT_ERROR / 3 to everyone else.
 *             if base_sum == 0:             # <<<<<<<<<<<<<<
 *                 unmapped_bases[i] = 1
 *                 reference_base = seq_bases[i]
 */
        goto __pyx_L33;
      }

      /* "_emirge_amplicon.pyx":385
 *                         probN_single[i, j] = p_div_3
 *             else: # has mappings.  adjust probs.
 *                 for j in range(4):             # <<<<<<<<<<<<<<
 *                     probN_single[i, j] = probN_single[i, j] / base_sum
 *         em.unmapped_bases[seq_i] = unmapped_bases.copy()
 */
      /*else*/ {
        for (__pyx_t_48 = 0; __pyx_t_48 < 4; __pyx_t_48+=1) {
          __pyx_v_j = __pyx_t_48;

          /* "_emirge_amplicon.pyx":386
 *             else: # has mappings.  adjust probs.
 *                 for j in range(4):
 *                     probN_single[i, j] = probN_single[i, j] / base_sum             # <<<<<<<<<<<<<<
 *         em.unmapped_bases[seq_i] = unmapped_bases.copy()
 * 
 */
          __pyx_t_91 = __pyx_v_i;
          __pyx_t_92 = __pyx_v_j;
          __pyx_t_93 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_91, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_92, __pyx_pybuffernd_probN_single.diminfo[1].strides));
          if (unlikely(__pyx_v_base_sum == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 386, __pyx_L1_error)
          }
          __pyx_t_94 = __pyx_v_i;
          __pyx_t_95 = __pyx_v_j;
          *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_probN_single.rcbuffer->pybuffer.buf, __pyx_t_94, __pyx_pybuffernd_probN_single.diminfo[0].strides, __pyx_t_95, __pyx_pybuffernd_probN_single.diminfo[1].strides) = (__pyx_t_93 / __pyx_v_base_sum);
        }
      }
      __pyx_L33:;
    }

    /* "_emirge_amplicon.pyx":387
 *                 for j in range(4):
 *                     probN_single[i, j] = probN_single[i, j] / base_sum
 *         em.unmapped_bases[seq_i] = unmapped_bases.copy()             # <<<<<<<<<<<<<<
 * 
 *     # print >> sys.stderr, "DEBUG: t_check 2: %s"%(timedelta(seconds = time() - t_check))
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_unmapped_bases), __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_79 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_79 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_79)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_79);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (__pyx_t_79) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_79); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_79); __pyx_t_79 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_unmapped_bases); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__Pyx_SetItemInt(__pyx_t_2, __pyx_v_seq_i, __pyx_t_1, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0) < 0)) __PYX_ERR(0, 387, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "_emirge_amplicon.pyx":357
 *     sequence_i2sequence_name_array = np.array(em.sequence_i2sequence_name)  # faster slicing. can't cdef string arrays yet.
 * 
 *     for seq_i, probN_single in enumerate(em.probN):             # <<<<<<<<<<<<<<
 *         if probN_single is None:  # means this sequence no longer present
 *             em.unmapped_bases[seq_i] = None
 */
    __pyx_L26_continue:;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "_emirge_amplicon.pyx":390
 * 
 *     # print >> sys.stderr, "DEBUG: t_check 2: %s"%(timedelta(seconds = time() - t_check))
 *     t_check = time()                    # DEBUG             # <<<<<<<<<<<<<<
 * 
 *     reads_seen |= reads_seen_this_round  # logical or equals, i.e. update newly seen reads this round
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 390, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_t_check, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "_emirge_amplicon.pyx":392
 *     t_check = time()                    # DEBUG
 * 
 *     reads_seen |= reads_seen_this_round  # logical or equals, i.e. update newly seen reads this round             # <<<<<<<<<<<<<<
 * 
 *     # print >> sys.stderr, "DEBUG: t_check 3: %s"%(timedelta(seconds = time() - t_check))
 */
  __pyx_t_8 = PyNumber_InPlaceOr(((PyObject *)__pyx_v_reads_seen), ((PyObject *)__pyx_v_reads_seen_this_round)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 392, __pyx_L1_error)
  __pyx_t_18 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer, (PyObject*)__pyx_v_reads_seen, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_15);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
      }
    }
    __pyx_pybuffernd_reads_seen.diminfo[0].strides = __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads_seen.diminfo[0].shape = __pyx_pybuffernd_reads_seen.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 392, __pyx_L1_error)
  }
  __pyx_t_18 = 0;
  __Pyx_DECREF_SET(__pyx_v_reads_seen, ((PyArrayObject *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "_emirge_amplicon.pyx":395
 * 
 *     # print >> sys.stderr, "DEBUG: t_check 3: %s"%(timedelta(seconds = time() - t_check))
 *     return             # <<<<<<<<<<<<<<
 * 
 * # will I want to add @cython.boundscheck(False) ?
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":198
 * 
 * @cython.boundscheck(False)
 * def _calc_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     helper function to emirge_amplicon.py calc_probN
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_79);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_priors.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seq_bases.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon._calc_probN", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dead_seqs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indices.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_indptr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_priors.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probN_single.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_seen.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_seen_this_round.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_seq_bases.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_unmapped_bases.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_reads);
  __Pyx_XDECREF((PyObject *)__pyx_v_quals);
  __Pyx_XDECREF((PyObject *)__pyx_v_bamfile_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_priors);
  __Pyx_XDECREF((PyObject *)__pyx_v_posteriors_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_posteriors_indices);
  __Pyx_XDECREF((PyObject *)__pyx_v_posteriors_indptr);
  __Pyx_XDECREF(__pyx_v_convert_t0);
  __Pyx_XDECREF(__pyx_v_posteriors);
  __Pyx_XDECREF(__pyx_v_t_check);
  __Pyx_XDECREF(__pyx_v_probN);
  __Pyx_XDECREF((PyObject *)__pyx_v_probN_single);
  __Pyx_XDECREF((PyObject *)__pyx_v_reads_seen);
  __Pyx_XDECREF((PyObject *)__pyx_v_reads_seen_this_round);
  __Pyx_XDECREF((PyObject *)__pyx_v_dead_seqs);
  __Pyx_XDECREF(__pyx_v_loop_t0);
  __Pyx_XDECREF(__pyx_v_lo);
  __Pyx_XDECREF(__pyx_v_td);
  __Pyx_XDECREF((PyObject *)__pyx_v_seq_bases);
  __Pyx_XDECREF((PyObject *)__pyx_v_unmapped_bases);
  __Pyx_XDECREF(__pyx_v_sequence_i2sequence_name_array);
  __Pyx_XDECREF(__pyx_v_py_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":399
 * # will I want to add @cython.boundscheck(False) ?
 * @cython.boundscheck(False)
 * def _calc_posteriors(em):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates Pr(S|R) for all sequence read pairs
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_5_calc_posteriors(PyObject *__pyx_self, PyObject *__pyx_v_em); /*proto*/
static char __pyx_doc_16_emirge_amplicon_4_calc_posteriors[] = "\n    Calculates Pr(S|R) for all sequence read pairs\n    requires that the likelihood and priors are already calculated.\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_5_calc_posteriors = {"_calc_posteriors", (PyCFunction)__pyx_pw_16_emirge_amplicon_5_calc_posteriors, METH_O, __pyx_doc_16_emirge_amplicon_4_calc_posteriors};
static PyObject *__pyx_pw_16_emirge_amplicon_5_calc_posteriors(PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calc_posteriors (wrapper)", 0);
  __pyx_r = __pyx_pf_16_emirge_amplicon_4_calc_posteriors(__pyx_self, ((PyObject *)__pyx_v_em));

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

static PyObject *__pyx_pf_16_emirge_amplicon_4_calc_posteriors(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_v_lik_coo = NULL;
  PyArrayObject *__pyx_v_lik_data = 0;
  PyArrayObject *__pyx_v_lik_row = 0;
  PyArrayObject *__pyx_v_lik_col = 0;
  PyArrayObject *__pyx_v_posteriors_data = 0;
  PyArrayObject *__pyx_v_priors = 0;
  PyArrayObject *__pyx_v_denominator = 0;
  unsigned int __pyx_v_i;
  float __pyx_v_product;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_denominator;
  __Pyx_Buffer __pyx_pybuffer_denominator;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_col;
  __Pyx_Buffer __pyx_pybuffer_lik_col;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_data;
  __Pyx_Buffer __pyx_pybuffer_lik_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lik_row;
  __Pyx_Buffer __pyx_pybuffer_lik_row;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_posteriors_data;
  __Pyx_Buffer __pyx_pybuffer_posteriors_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_priors;
  __Pyx_Buffer __pyx_pybuffer_priors;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyArrayObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  npy_intp __pyx_t_12;
  unsigned int __pyx_t_13;
  size_t __pyx_t_14;
  size_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  size_t __pyx_t_17;
  size_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  size_t __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  int __pyx_t_22;
  size_t __pyx_t_23;
  size_t __pyx_t_24;
  __pyx_t_5numpy_float_t __pyx_t_25;
  size_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  __pyx_t_5numpy_float_t __pyx_t_28;
  size_t __pyx_t_29;
  __Pyx_RefNannySetupContext("_calc_posteriors", 0);
  __pyx_pybuffer_lik_data.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_data.refcount = 0;
  __pyx_pybuffernd_lik_data.data = NULL;
  __pyx_pybuffernd_lik_data.rcbuffer = &__pyx_pybuffer_lik_data;
  __pyx_pybuffer_lik_row.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_row.refcount = 0;
  __pyx_pybuffernd_lik_row.data = NULL;
  __pyx_pybuffernd_lik_row.rcbuffer = &__pyx_pybuffer_lik_row;
  __pyx_pybuffer_lik_col.pybuffer.buf = NULL;
  __pyx_pybuffer_lik_col.refcount = 0;
  __pyx_pybuffernd_lik_col.data = NULL;
  __pyx_pybuffernd_lik_col.rcbuffer = &__pyx_pybuffer_lik_col;
  __pyx_pybuffer_posteriors_data.pybuffer.buf = NULL;
  __pyx_pybuffer_posteriors_data.refcount = 0;
  __pyx_pybuffernd_posteriors_data.data = NULL;
  __pyx_pybuffernd_posteriors_data.rcbuffer = &__pyx_pybuffer_posteriors_data;
  __pyx_pybuffer_priors.pybuffer.buf = NULL;
  __pyx_pybuffer_priors.refcount = 0;
  __pyx_pybuffernd_priors.data = NULL;
  __pyx_pybuffernd_priors.rcbuffer = &__pyx_pybuffer_priors;
  __pyx_pybuffer_denominator.pybuffer.buf = NULL;
  __pyx_pybuffer_denominator.refcount = 0;
  __pyx_pybuffernd_denominator.data = NULL;
  __pyx_pybuffernd_denominator.rcbuffer = &__pyx_pybuffer_denominator;

  /* "_emirge_amplicon.pyx":407
 *     # Go through coo lik, putting numerator in posterior and adding to denom sum as you go.
 *     # lik and post are (seq_n x read_n)
 *     lik_coo = em.likelihoods.tocoo()             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data = lik_coo.data
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_row = lik_coo.row
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_likelihoods); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 407, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_tocoo); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 407, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 407, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_lik_coo = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":408
 *     # lik and post are (seq_n x read_n)
 *     lik_coo = em.likelihoods.tocoo()
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data = lik_coo.data             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_row = lik_coo.row
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_col = lik_coo.col
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_lik_coo, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 408, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 408, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_data.diminfo[0].strides = __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_data.diminfo[0].shape = __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_4 = 0;
  __pyx_v_lik_data = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":409
 *     lik_coo = em.likelihoods.tocoo()
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data = lik_coo.data
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_row = lik_coo.row             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_col = lik_coo.col
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_lik_coo, __pyx_n_s_row); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 409, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 409, __pyx_L1_error)
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_row.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_row = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_row.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 409, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_row.diminfo[0].strides = __pyx_pybuffernd_lik_row.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_row.diminfo[0].shape = __pyx_pybuffernd_lik_row.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_5 = 0;
  __pyx_v_lik_row = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":410
 *     cdef np.ndarray[np.float_t, ndim=1] lik_data = lik_coo.data
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_row = lik_coo.row
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_col = lik_coo.col             # <<<<<<<<<<<<<<
 * 
 *     cdef np.ndarray[np.float_t, ndim=1] posteriors_data = np.zeros_like(lik_coo.data)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_lik_coo, __pyx_n_s_col); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 410, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 410, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lik_col.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lik_col = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 410, __pyx_L1_error)
    } else {__pyx_pybuffernd_lik_col.diminfo[0].strides = __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lik_col.diminfo[0].shape = __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_lik_col = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":412
 *     cdef np.ndarray[np.int32_t, ndim=1] lik_col = lik_coo.col
 * 
 *     cdef np.ndarray[np.float_t, ndim=1] posteriors_data = np.zeros_like(lik_coo.data)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.float_t, ndim=1] priors = np.array(em.priors[-2], dtype = np.float)
 *     cdef np.ndarray[np.float_t, ndim=1] denominator = np.zeros(em.n_reads, dtype=np.float)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lik_coo, __pyx_n_s_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_3};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_3};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 412, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_posteriors_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 412, __pyx_L1_error)
    } else {__pyx_pybuffernd_posteriors_data.diminfo[0].strides = __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_posteriors_data.diminfo[0].shape = __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_posteriors_data = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":413
 * 
 *     cdef np.ndarray[np.float_t, ndim=1] posteriors_data = np.zeros_like(lik_coo.data)
 *     cdef np.ndarray[np.float_t, ndim=1] priors = np.array(em.priors[-2], dtype = np.float)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.float_t, ndim=1] denominator = np.zeros(em.n_reads, dtype=np.float)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_priors); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_1, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 413, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_priors.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_priors = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_priors.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 413, __pyx_L1_error)
    } else {__pyx_pybuffernd_priors.diminfo[0].strides = __pyx_pybuffernd_priors.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_priors.diminfo[0].shape = __pyx_pybuffernd_priors.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_priors = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":414
 *     cdef np.ndarray[np.float_t, ndim=1] posteriors_data = np.zeros_like(lik_coo.data)
 *     cdef np.ndarray[np.float_t, ndim=1] priors = np.array(em.priors[-2], dtype = np.float)
 *     cdef np.ndarray[np.float_t, ndim=1] denominator = np.zeros(em.n_reads, dtype=np.float)             # <<<<<<<<<<<<<<
 * 
 *     cdef unsigned int i
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_n_reads); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 414, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_denominator.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_denominator = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_denominator.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 414, __pyx_L1_error)
    } else {__pyx_pybuffernd_denominator.diminfo[0].strides = __pyx_pybuffernd_denominator.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_denominator.diminfo[0].shape = __pyx_pybuffernd_denominator.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_11 = 0;
  __pyx_v_denominator = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "_emirge_amplicon.pyx":419
 *     cdef float product
 * 
 *     for i in range(posteriors_data.shape[0]):             # <<<<<<<<<<<<<<
 *         # lik_row[i] should be row in posteriors matrix, which should be seq_i
 *         product = lik_data[i] * priors[lik_row[i]]
 */
  __pyx_t_12 = (__pyx_v_posteriors_data->dimensions[0]);
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_i = __pyx_t_13;

    /* "_emirge_amplicon.pyx":421
 *     for i in range(posteriors_data.shape[0]):
 *         # lik_row[i] should be row in posteriors matrix, which should be seq_i
 *         product = lik_data[i] * priors[lik_row[i]]             # <<<<<<<<<<<<<<
 *         posteriors_data[i] = product
 *         # lik_col[i] should return read_i
 */
    __pyx_t_14 = __pyx_v_i;
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_16 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_lik_row.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_lik_row.diminfo[0].strides));
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_pybuffernd_priors.diminfo[0].shape;
    __pyx_v_product = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_lik_data.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_lik_data.diminfo[0].strides)) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_priors.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_priors.diminfo[0].strides)));

    /* "_emirge_amplicon.pyx":422
 *         # lik_row[i] should be row in posteriors matrix, which should be seq_i
 *         product = lik_data[i] * priors[lik_row[i]]
 *         posteriors_data[i] = product             # <<<<<<<<<<<<<<
 *         # lik_col[i] should return read_i
 *         denominator[lik_col[i]] += product
 */
    __pyx_t_17 = __pyx_v_i;
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_posteriors_data.diminfo[0].strides) = __pyx_v_product;

    /* "_emirge_amplicon.pyx":424
 *         posteriors_data[i] = product
 *         # lik_col[i] should return read_i
 *         denominator[lik_col[i]] += product             # <<<<<<<<<<<<<<
 * 
 *     # make second pass through posterior coo, dividing data by denom sum for that read.
 */
    __pyx_t_18 = __pyx_v_i;
    __pyx_t_19 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_lik_col.diminfo[0].strides));
    if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_pybuffernd_denominator.diminfo[0].shape;
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_denominator.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_denominator.diminfo[0].strides) += __pyx_v_product;
  }

  /* "_emirge_amplicon.pyx":427
 * 
 *     # make second pass through posterior coo, dividing data by denom sum for that read.
 *     for i in range(posteriors_data.shape[0]):             # <<<<<<<<<<<<<<
 *         if denominator[lik_col[i]] == 0:  # e.g. if prior was 0
 *             # assert posteriors_data[i] == 0
 */
  __pyx_t_12 = (__pyx_v_posteriors_data->dimensions[0]);
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_i = __pyx_t_13;

    /* "_emirge_amplicon.pyx":428
 *     # make second pass through posterior coo, dividing data by denom sum for that read.
 *     for i in range(posteriors_data.shape[0]):
 *         if denominator[lik_col[i]] == 0:  # e.g. if prior was 0             # <<<<<<<<<<<<<<
 *             # assert posteriors_data[i] == 0
 *             posteriors_data[i] = 0
 */
    __pyx_t_20 = __pyx_v_i;
    __pyx_t_21 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_lik_col.diminfo[0].strides));
    if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_pybuffernd_denominator.diminfo[0].shape;
    __pyx_t_22 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_denominator.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_denominator.diminfo[0].strides)) == 0.0) != 0);
    if (__pyx_t_22) {

      /* "_emirge_amplicon.pyx":430
 *         if denominator[lik_col[i]] == 0:  # e.g. if prior was 0
 *             # assert posteriors_data[i] == 0
 *             posteriors_data[i] = 0             # <<<<<<<<<<<<<<
 *         else:
 *             posteriors_data[i] = posteriors_data[i] / denominator[lik_col[i]]
 */
      __pyx_t_23 = __pyx_v_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_posteriors_data.diminfo[0].strides) = 0.0;

      /* "_emirge_amplicon.pyx":428
 *     # make second pass through posterior coo, dividing data by denom sum for that read.
 *     for i in range(posteriors_data.shape[0]):
 *         if denominator[lik_col[i]] == 0:  # e.g. if prior was 0             # <<<<<<<<<<<<<<
 *             # assert posteriors_data[i] == 0
 *             posteriors_data[i] = 0
 */
      goto __pyx_L7;
    }

    /* "_emirge_amplicon.pyx":432
 *             posteriors_data[i] = 0
 *         else:
 *             posteriors_data[i] = posteriors_data[i] / denominator[lik_col[i]]             # <<<<<<<<<<<<<<
 * 
 *     # now replace most recent posterior data structure with this built one (in coo format)
 */
    /*else*/ {
      __pyx_t_24 = __pyx_v_i;
      __pyx_t_25 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_posteriors_data.diminfo[0].strides));
      __pyx_t_26 = __pyx_v_i;
      __pyx_t_27 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_lik_col.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_lik_col.diminfo[0].strides));
      if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_pybuffernd_denominator.diminfo[0].shape;
      __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_denominator.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_denominator.diminfo[0].strides));
      if (unlikely(__pyx_t_28 == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 432, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_i;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_posteriors_data.diminfo[0].strides) = (__pyx_t_25 / __pyx_t_28);
    }
    __pyx_L7:;
  }

  /* "_emirge_amplicon.pyx":435
 * 
 *     # now replace most recent posterior data structure with this built one (in coo format)
 *     em.posteriors[-1] = sparse.coo_matrix((posteriors_data, (lik_row, lik_col)), shape=em.likelihoods.shape, dtype=em.posteriors[-1].dtype)             # <<<<<<<<<<<<<<
 *     return
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_sparse); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_coo_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_lik_row));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_row));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_lik_row));
  __Pyx_INCREF(((PyObject *)__pyx_v_lik_col));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lik_col));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_lik_col));
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_posteriors_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_posteriors_data));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_posteriors_data));
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_likelihoods); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_2) < 0) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_2, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_posteriors); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__Pyx_SetItemInt(__pyx_t_1, -1L, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 0, 1, 0) < 0)) __PYX_ERR(0, 435, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":436
 *     # now replace most recent posterior data structure with this built one (in coo format)
 *     em.posteriors[-1] = sparse.coo_matrix((posteriors_data, (lik_row, lik_col)), shape=em.likelihoods.shape, dtype=em.posteriors[-1].dtype)
 *     return             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":399
 * # will I want to add @cython.boundscheck(False) ?
 * @cython.boundscheck(False)
 * def _calc_posteriors(em):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates Pr(S|R) for all sequence read pairs
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_denominator.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_col.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_row.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_priors.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon._calc_posteriors", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_denominator.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_col.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lik_row.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_posteriors_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_priors.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_lik_coo);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_row);
  __Pyx_XDECREF((PyObject *)__pyx_v_lik_col);
  __Pyx_XDECREF((PyObject *)__pyx_v_posteriors_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_priors);
  __Pyx_XDECREF((PyObject *)__pyx_v_denominator);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":439
 * 
 * 
 * def count_cigar_aln(char* query_seq, char* hit_seq,             # <<<<<<<<<<<<<<
 *                     np.ndarray[np.uint8_t, ndim=1] query_unmapped_bases,
 *                     np.ndarray[np.uint8_t, ndim=1] hit_unmapped_bases,
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_7count_cigar_aln(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_16_emirge_amplicon_6count_cigar_aln[] = "\n    alncode list comes from a cigar string (see call in emirge_amplicon.py)\n    \n    returns number of aligned columns and number of matches in those aligned columns as tuple\n    only includes columns where both sequences have mapped bases\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_7count_cigar_aln = {"count_cigar_aln", (PyCFunction)__pyx_pw_16_emirge_amplicon_7count_cigar_aln, METH_VARARGS|METH_KEYWORDS, __pyx_doc_16_emirge_amplicon_6count_cigar_aln};
static PyObject *__pyx_pw_16_emirge_amplicon_7count_cigar_aln(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_query_seq;
  char *__pyx_v_hit_seq;
  PyArrayObject *__pyx_v_query_unmapped_bases = 0;
  PyArrayObject *__pyx_v_hit_unmapped_bases = 0;
  unsigned int __pyx_v_query_i;
  unsigned int __pyx_v_hit_i;
  PyObject *__pyx_v_alncode_list = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count_cigar_aln (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_seq,&__pyx_n_s_hit_seq,&__pyx_n_s_query_unmapped_bases,&__pyx_n_s_hit_unmapped_bases,&__pyx_n_s_query_i,&__pyx_n_s_hit_i,&__pyx_n_s_alncode_list,0};
    PyObject* values[7] = {0,0,0,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  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_seq)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hit_seq)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 1); __PYX_ERR(0, 439, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_unmapped_bases)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 2); __PYX_ERR(0, 439, __pyx_L3_error)
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hit_unmapped_bases)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 3); __PYX_ERR(0, 439, __pyx_L3_error)
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query_i)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 4); __PYX_ERR(0, 439, __pyx_L3_error)
        }
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_hit_i)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 5); __PYX_ERR(0, 439, __pyx_L3_error)
        }
        case  6:
        if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alncode_list)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, 6); __PYX_ERR(0, 439, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_cigar_aln") < 0)) __PYX_ERR(0, 439, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
      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);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
    }
    __pyx_v_query_seq = __Pyx_PyObject_AsString(values[0]); if (unlikely((!__pyx_v_query_seq) && PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L3_error)
    __pyx_v_hit_seq = __Pyx_PyObject_AsString(values[1]); if (unlikely((!__pyx_v_hit_seq) && PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L3_error)
    __pyx_v_query_unmapped_bases = ((PyArrayObject *)values[2]);
    __pyx_v_hit_unmapped_bases = ((PyArrayObject *)values[3]);
    __pyx_v_query_i = __Pyx_PyInt_As_unsigned_int(values[4]); if (unlikely((__pyx_v_query_i == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 442, __pyx_L3_error)
    __pyx_v_hit_i = __Pyx_PyInt_As_unsigned_int(values[5]); if (unlikely((__pyx_v_hit_i == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 443, __pyx_L3_error)
    __pyx_v_alncode_list = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count_cigar_aln", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 439, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_emirge_amplicon.count_cigar_aln", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query_unmapped_bases), __pyx_ptype_5numpy_ndarray, 1, "query_unmapped_bases", 0))) __PYX_ERR(0, 440, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hit_unmapped_bases), __pyx_ptype_5numpy_ndarray, 1, "hit_unmapped_bases", 0))) __PYX_ERR(0, 441, __pyx_L1_error)
  __pyx_r = __pyx_pf_16_emirge_amplicon_6count_cigar_aln(__pyx_self, __pyx_v_query_seq, __pyx_v_hit_seq, __pyx_v_query_unmapped_bases, __pyx_v_hit_unmapped_bases, __pyx_v_query_i, __pyx_v_hit_i, __pyx_v_alncode_list);

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

static PyObject *__pyx_pf_16_emirge_amplicon_6count_cigar_aln(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_query_seq, char *__pyx_v_hit_seq, PyArrayObject *__pyx_v_query_unmapped_bases, PyArrayObject *__pyx_v_hit_unmapped_bases, unsigned int __pyx_v_query_i, unsigned int __pyx_v_hit_i, PyObject *__pyx_v_alncode_list) {
  int __pyx_v_matches;
  int __pyx_v_aln_columns;
  int __pyx_v_count;
  int __pyx_v_i;
  int __pyx_v_j;
  PyObject *__pyx_v_count_a = NULL;
  PyObject *__pyx_v_aln_code = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hit_unmapped_bases;
  __Pyx_Buffer __pyx_pybuffer_hit_unmapped_bases;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_query_unmapped_bases;
  __Pyx_Buffer __pyx_pybuffer_query_unmapped_bases;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  size_t __pyx_t_12;
  int __pyx_t_13;
  size_t __pyx_t_14;
  __Pyx_RefNannySetupContext("count_cigar_aln", 0);
  __pyx_pybuffer_query_unmapped_bases.pybuffer.buf = NULL;
  __pyx_pybuffer_query_unmapped_bases.refcount = 0;
  __pyx_pybuffernd_query_unmapped_bases.data = NULL;
  __pyx_pybuffernd_query_unmapped_bases.rcbuffer = &__pyx_pybuffer_query_unmapped_bases;
  __pyx_pybuffer_hit_unmapped_bases.pybuffer.buf = NULL;
  __pyx_pybuffer_hit_unmapped_bases.refcount = 0;
  __pyx_pybuffernd_hit_unmapped_bases.data = NULL;
  __pyx_pybuffernd_hit_unmapped_bases.rcbuffer = &__pyx_pybuffer_hit_unmapped_bases;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer, (PyObject*)__pyx_v_query_unmapped_bases, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 439, __pyx_L1_error)
  }
  __pyx_pybuffernd_query_unmapped_bases.diminfo[0].strides = __pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_query_unmapped_bases.diminfo[0].shape = __pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer, (PyObject*)__pyx_v_hit_unmapped_bases, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 439, __pyx_L1_error)
  }
  __pyx_pybuffernd_hit_unmapped_bases.diminfo[0].strides = __pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hit_unmapped_bases.diminfo[0].shape = __pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer.shape[0];

  /* "_emirge_amplicon.pyx":454
 *     # cdef unsigned int query_i = query_start  # 0   # for global alignment, this used to always be zero.
 *     # cdef unsigned int hit_i   = hit_start    # 0
 *     cdef int matches = 0             # <<<<<<<<<<<<<<
 *     cdef int aln_columns    = 0
 *     cdef int count
 */
  __pyx_v_matches = 0;

  /* "_emirge_amplicon.pyx":455
 *     # cdef unsigned int hit_i   = hit_start    # 0
 *     cdef int matches = 0
 *     cdef int aln_columns    = 0             # <<<<<<<<<<<<<<
 *     cdef int count
 *     # cdef char aln_code  # doesn't work.  Expects integer
 */
  __pyx_v_aln_columns = 0;

  /* "_emirge_amplicon.pyx":461
 *     cdef int j
 * 
 *     for i in range(len(alncode_list)):             # <<<<<<<<<<<<<<
 *         count_a, aln_code = alncode_list[i]
 *         # print >> sys.stderr, "***", count_a, aln_code, len(query_seq), len(query_unmapped_bases), len(hit_seq), len(hit_unmapped_bases)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_alncode_list); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 461, __pyx_L1_error)
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_i = __pyx_t_2;

    /* "_emirge_amplicon.pyx":462
 * 
 *     for i in range(len(alncode_list)):
 *         count_a, aln_code = alncode_list[i]             # <<<<<<<<<<<<<<
 *         # print >> sys.stderr, "***", count_a, aln_code, len(query_seq), len(query_unmapped_bases), len(hit_seq), len(hit_unmapped_bases)
 *         if not len(count_a):
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_alncode_list, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      #if !CYTHON_COMPILING_IN_PYPY
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 462, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      #else
      __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 462, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 462, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 462, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
      index = 0; __pyx_t_4 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 462, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 462, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_count_a, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_aln_code, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "_emirge_amplicon.pyx":464
 *         count_a, aln_code = alncode_list[i]
 *         # print >> sys.stderr, "***", count_a, aln_code, len(query_seq), len(query_unmapped_bases), len(hit_seq), len(hit_unmapped_bases)
 *         if not len(count_a):             # <<<<<<<<<<<<<<
 *             count = 1  # "As a special case, if n=1 then n is omitted"
 *         else:
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_count_a); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 464, __pyx_L1_error)
    __pyx_t_9 = ((!(__pyx_t_8 != 0)) != 0);
    if (__pyx_t_9) {

      /* "_emirge_amplicon.pyx":465
 *         # print >> sys.stderr, "***", count_a, aln_code, len(query_seq), len(query_unmapped_bases), len(hit_seq), len(hit_unmapped_bases)
 *         if not len(count_a):
 *             count = 1  # "As a special case, if n=1 then n is omitted"             # <<<<<<<<<<<<<<
 *         else:
 *             count = int(count_a)
 */
      __pyx_v_count = 1;

      /* "_emirge_amplicon.pyx":464
 *         count_a, aln_code = alncode_list[i]
 *         # print >> sys.stderr, "***", count_a, aln_code, len(query_seq), len(query_unmapped_bases), len(hit_seq), len(hit_unmapped_bases)
 *         if not len(count_a):             # <<<<<<<<<<<<<<
 *             count = 1  # "As a special case, if n=1 then n is omitted"
 *         else:
 */
      goto __pyx_L7;
    }

    /* "_emirge_amplicon.pyx":467
 *             count = 1  # "As a special case, if n=1 then n is omitted"
 *         else:
 *             count = int(count_a)             # <<<<<<<<<<<<<<
 * 
 *         if aln_code == 'M':    # match (letter-letter column; could be mismatch)
 */
    /*else*/ {
      __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_v_count_a); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_count = __pyx_t_10;
    }
    __pyx_L7:;

    /* "_emirge_amplicon.pyx":469
 *             count = int(count_a)
 * 
 *         if aln_code == 'M':    # match (letter-letter column; could be mismatch)             # <<<<<<<<<<<<<<
 *             for j in range(count):
 *                 # print >> sys.stderr, "***", query_i+j, hit_i+j, query_seq[query_i+j], hit_seq[hit_i+j]
 */
    __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_aln_code, __pyx_n_s_M, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 469, __pyx_L1_error)
    if (__pyx_t_9) {

      /* "_emirge_amplicon.pyx":470
 * 
 *         if aln_code == 'M':    # match (letter-letter column; could be mismatch)
 *             for j in range(count):             # <<<<<<<<<<<<<<
 *                 # print >> sys.stderr, "***", query_i+j, hit_i+j, query_seq[query_i+j], hit_seq[hit_i+j]
 * 
 */
      __pyx_t_10 = __pyx_v_count;
      for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
        __pyx_v_j = __pyx_t_11;

        /* "_emirge_amplicon.pyx":473
 *                 # print >> sys.stderr, "***", query_i+j, hit_i+j, query_seq[query_i+j], hit_seq[hit_i+j]
 * 
 *                 if query_unmapped_bases[query_i+j] == 0:             # <<<<<<<<<<<<<<
 *                     if hit_unmapped_bases[hit_i+j] == 0:
 *                         aln_columns += 1
 */
        __pyx_t_12 = (__pyx_v_query_i + __pyx_v_j);
        __pyx_t_13 = -1;
        if (unlikely(__pyx_t_12 >= (size_t)__pyx_pybuffernd_query_unmapped_bases.diminfo[0].shape)) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 473, __pyx_L1_error)
        }
        __pyx_t_9 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_query_unmapped_bases.diminfo[0].strides)) == 0) != 0);
        if (__pyx_t_9) {

          /* "_emirge_amplicon.pyx":474
 * 
 *                 if query_unmapped_bases[query_i+j] == 0:
 *                     if hit_unmapped_bases[hit_i+j] == 0:             # <<<<<<<<<<<<<<
 *                         aln_columns += 1
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:
 */
          __pyx_t_14 = (__pyx_v_hit_i + __pyx_v_j);
          __pyx_t_13 = -1;
          if (unlikely(__pyx_t_14 >= (size_t)__pyx_pybuffernd_hit_unmapped_bases.diminfo[0].shape)) __pyx_t_13 = 0;
          if (unlikely(__pyx_t_13 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_13);
            __PYX_ERR(0, 474, __pyx_L1_error)
          }
          __pyx_t_9 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_hit_unmapped_bases.diminfo[0].strides)) == 0) != 0);
          if (__pyx_t_9) {

            /* "_emirge_amplicon.pyx":475
 *                 if query_unmapped_bases[query_i+j] == 0:
 *                     if hit_unmapped_bases[hit_i+j] == 0:
 *                         aln_columns += 1             # <<<<<<<<<<<<<<
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:
 *                             matches += 1
 */
            __pyx_v_aln_columns = (__pyx_v_aln_columns + 1);

            /* "_emirge_amplicon.pyx":476
 *                     if hit_unmapped_bases[hit_i+j] == 0:
 *                         aln_columns += 1
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:             # <<<<<<<<<<<<<<
 *                             matches += 1
 *             query_i += count
 */
            __pyx_t_9 = (((__pyx_v_query_seq[(__pyx_v_query_i + __pyx_v_j)]) == (__pyx_v_hit_seq[(__pyx_v_hit_i + __pyx_v_j)])) != 0);
            if (__pyx_t_9) {

              /* "_emirge_amplicon.pyx":477
 *                         aln_columns += 1
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:
 *                             matches += 1             # <<<<<<<<<<<<<<
 *             query_i += count
 *             hit_i += count
 */
              __pyx_v_matches = (__pyx_v_matches + 1);

              /* "_emirge_amplicon.pyx":476
 *                     if hit_unmapped_bases[hit_i+j] == 0:
 *                         aln_columns += 1
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:             # <<<<<<<<<<<<<<
 *                             matches += 1
 *             query_i += count
 */
            }

            /* "_emirge_amplicon.pyx":474
 * 
 *                 if query_unmapped_bases[query_i+j] == 0:
 *                     if hit_unmapped_bases[hit_i+j] == 0:             # <<<<<<<<<<<<<<
 *                         aln_columns += 1
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:
 */
          }

          /* "_emirge_amplicon.pyx":473
 *                 # print >> sys.stderr, "***", query_i+j, hit_i+j, query_seq[query_i+j], hit_seq[hit_i+j]
 * 
 *                 if query_unmapped_bases[query_i+j] == 0:             # <<<<<<<<<<<<<<
 *                     if hit_unmapped_bases[hit_i+j] == 0:
 *                         aln_columns += 1
 */
        }
      }

      /* "_emirge_amplicon.pyx":478
 *                         if query_seq[query_i+j] == hit_seq[hit_i+j]:
 *                             matches += 1
 *             query_i += count             # <<<<<<<<<<<<<<
 *             hit_i += count
 *         elif aln_code == 'I':
 */
      __pyx_v_query_i = (__pyx_v_query_i + __pyx_v_count);

      /* "_emirge_amplicon.pyx":479
 *                             matches += 1
 *             query_i += count
 *             hit_i += count             # <<<<<<<<<<<<<<
 *         elif aln_code == 'I':
 *             query_i += count
 */
      __pyx_v_hit_i = (__pyx_v_hit_i + __pyx_v_count);

      /* "_emirge_amplicon.pyx":469
 *             count = int(count_a)
 * 
 *         if aln_code == 'M':    # match (letter-letter column; could be mismatch)             # <<<<<<<<<<<<<<
 *             for j in range(count):
 *                 # print >> sys.stderr, "***", query_i+j, hit_i+j, query_seq[query_i+j], hit_seq[hit_i+j]
 */
      goto __pyx_L8;
    }

    /* "_emirge_amplicon.pyx":480
 *             query_i += count
 *             hit_i += count
 *         elif aln_code == 'I':             # <<<<<<<<<<<<<<
 *             query_i += count
 *         elif aln_code == 'D':
 */
    __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_aln_code, __pyx_n_s_I, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 480, __pyx_L1_error)
    if (__pyx_t_9) {

      /* "_emirge_amplicon.pyx":481
 *             hit_i += count
 *         elif aln_code == 'I':
 *             query_i += count             # <<<<<<<<<<<<<<
 *         elif aln_code == 'D':
 *             hit_i += count
 */
      __pyx_v_query_i = (__pyx_v_query_i + __pyx_v_count);

      /* "_emirge_amplicon.pyx":480
 *             query_i += count
 *             hit_i += count
 *         elif aln_code == 'I':             # <<<<<<<<<<<<<<
 *             query_i += count
 *         elif aln_code == 'D':
 */
      goto __pyx_L8;
    }

    /* "_emirge_amplicon.pyx":482
 *         elif aln_code == 'I':
 *             query_i += count
 *         elif aln_code == 'D':             # <<<<<<<<<<<<<<
 *             hit_i += count
 *         else:
 */
    __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_aln_code, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 482, __pyx_L1_error)
    if (__pyx_t_9) {

      /* "_emirge_amplicon.pyx":483
 *             query_i += count
 *         elif aln_code == 'D':
 *             hit_i += count             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError, "unknown alignment code: '%s'"%aln_code
 */
      __pyx_v_hit_i = (__pyx_v_hit_i + __pyx_v_count);

      /* "_emirge_amplicon.pyx":482
 *         elif aln_code == 'I':
 *             query_i += count
 *         elif aln_code == 'D':             # <<<<<<<<<<<<<<
 *             hit_i += count
 *         else:
 */
      goto __pyx_L8;
    }

    /* "_emirge_amplicon.pyx":485
 *             hit_i += count
 *         else:
 *             raise ValueError, "unknown alignment code: '%s'"%aln_code             # <<<<<<<<<<<<<<
 * 
 *     return aln_columns, matches
 */
    /*else*/ {
      __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_unknown_alignment_code_s, __pyx_v_aln_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_builtin_ValueError, __pyx_t_3, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 485, __pyx_L1_error)
    }
    __pyx_L8:;
  }

  /* "_emirge_amplicon.pyx":487
 *             raise ValueError, "unknown alignment code: '%s'"%aln_code
 * 
 *     return aln_columns, matches             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_aln_columns); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_matches); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":439
 * 
 * 
 * def count_cigar_aln(char* query_seq, char* hit_seq,             # <<<<<<<<<<<<<<
 *                     np.ndarray[np.uint8_t, ndim=1] query_unmapped_bases,
 *                     np.ndarray[np.uint8_t, ndim=1] hit_unmapped_bases,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon.count_cigar_aln", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hit_unmapped_bases.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_query_unmapped_bases.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_count_a);
  __Pyx_XDECREF(__pyx_v_aln_code);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":490
 * 
 * 
 * def populate_reads_arrays(em):             # <<<<<<<<<<<<<<
 *     """
 *     2.  populates:
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_9populate_reads_arrays(PyObject *__pyx_self, PyObject *__pyx_v_em); /*proto*/
static char __pyx_doc_16_emirge_amplicon_8populate_reads_arrays[] = "\n    2.  populates:\n            em.reads\n            em.quals\n            em.readlengths\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_9populate_reads_arrays = {"populate_reads_arrays", (PyCFunction)__pyx_pw_16_emirge_amplicon_9populate_reads_arrays, METH_O, __pyx_doc_16_emirge_amplicon_8populate_reads_arrays};
static PyObject *__pyx_pw_16_emirge_amplicon_9populate_reads_arrays(PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("populate_reads_arrays (wrapper)", 0);
  __pyx_r = __pyx_pf_16_emirge_amplicon_8populate_reads_arrays(__pyx_self, ((PyObject *)__pyx_v_em));

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

static PyObject *__pyx_pf_16_emirge_amplicon_8populate_reads_arrays(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyArrayObject *__pyx_v_reads = 0;
  PyArrayObject *__pyx_v_quals = 0;
  PyArrayObject *__pyx_v_readlengths = 0;
  unsigned int __pyx_v_read_index;
  unsigned int __pyx_v_readtype_index;
  unsigned int __pyx_v_i;
  int __pyx_v_ascii_offset;
  struct __pyx_obj_6pykseq_Kseq *__pyx_v_ks = 0;
  __pyx_t_6pykseq_kseq_t_pointer __pyx_v_ks_p;
  PyObject *__pyx_v_reads_filepath = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_quals;
  __Pyx_Buffer __pyx_pybuffer_quals;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_readlengths;
  __Pyx_Buffer __pyx_pybuffer_readlengths;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads;
  __Pyx_Buffer __pyx_pybuffer_reads;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyArrayObject *__pyx_t_2 = NULL;
  PyArrayObject *__pyx_t_3 = NULL;
  PyArrayObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  unsigned int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  size_t __pyx_t_15;
  int __pyx_t_16;
  size_t __pyx_t_17;
  size_t __pyx_t_18;
  size_t __pyx_t_19;
  __Pyx_RefNannySetupContext("populate_reads_arrays", 0);
  __pyx_pybuffer_reads.pybuffer.buf = NULL;
  __pyx_pybuffer_reads.refcount = 0;
  __pyx_pybuffernd_reads.data = NULL;
  __pyx_pybuffernd_reads.rcbuffer = &__pyx_pybuffer_reads;
  __pyx_pybuffer_quals.pybuffer.buf = NULL;
  __pyx_pybuffer_quals.refcount = 0;
  __pyx_pybuffernd_quals.data = NULL;
  __pyx_pybuffernd_quals.rcbuffer = &__pyx_pybuffer_quals;
  __pyx_pybuffer_readlengths.pybuffer.buf = NULL;
  __pyx_pybuffer_readlengths.refcount = 0;
  __pyx_pybuffernd_readlengths.data = NULL;
  __pyx_pybuffernd_readlengths.rcbuffer = &__pyx_pybuffer_readlengths;

  /* "_emirge_amplicon.pyx":497
 *             em.readlengths
 *     """
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # n_reads X pair X max_read_length             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef np.ndarray[np.uint16_t, ndim=2] readlengths = em.readlengths
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 497, __pyx_L1_error)
  __pyx_t_2 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_reads = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 497, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads.diminfo[0].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads.diminfo[0].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_reads.diminfo[1].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_reads.diminfo[1].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_reads.diminfo[2].strides = __pyx_pybuffernd_reads.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_reads.diminfo[2].shape = __pyx_pybuffernd_reads.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_2 = 0;
  __pyx_v_reads = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":498
 *     """
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # n_reads X pair X max_read_length
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint16_t, ndim=2] readlengths = em.readlengths
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_quals); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 498, __pyx_L1_error)
  __pyx_t_3 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quals.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_quals = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 498, __pyx_L1_error)
    } else {__pyx_pybuffernd_quals.diminfo[0].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quals.diminfo[0].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quals.diminfo[1].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quals.diminfo[1].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quals.diminfo[2].strides = __pyx_pybuffernd_quals.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quals.diminfo[2].shape = __pyx_pybuffernd_quals.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_3 = 0;
  __pyx_v_quals = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":499
 *     cdef np.ndarray[np.uint8_t, ndim=3] reads = em.reads  # n_reads X pair X max_read_length
 *     cdef np.ndarray[np.uint8_t, ndim=3] quals = em.quals
 *     cdef np.ndarray[np.uint16_t, ndim=2] readlengths = em.readlengths             # <<<<<<<<<<<<<<
 * 
 *     cdef unsigned int read_index
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_readlengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 499, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 499, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_readlengths.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_readlengths = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_readlengths.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 499, __pyx_L1_error)
    } else {__pyx_pybuffernd_readlengths.diminfo[0].strides = __pyx_pybuffernd_readlengths.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_readlengths.diminfo[0].shape = __pyx_pybuffernd_readlengths.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_readlengths.diminfo[1].strides = __pyx_pybuffernd_readlengths.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_readlengths.diminfo[1].shape = __pyx_pybuffernd_readlengths.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_4 = 0;
  __pyx_v_readlengths = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":505
 *     cdef int readlength
 *     cdef unsigned int i
 *     cdef int ascii_offset = em.reads_ascii_offset             # <<<<<<<<<<<<<<
 * 
 *     cdef pykseq.Kseq ks
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads_ascii_offset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ascii_offset = __pyx_t_5;

  /* "_emirge_amplicon.pyx":511
 * 
 *     # first do /1 reads, then do /2 reads if present
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),             # <<<<<<<<<<<<<<
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads1_filepath); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_0);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":512
 *     # first do /1 reads, then do /2 reads if present
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),
 *                                            (em.reads2_filepath, 1)]:             # <<<<<<<<<<<<<<
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 *             continue
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_reads2_filepath); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":511
 * 
 *     # first do /1 reads, then do /2 reads if present
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),             # <<<<<<<<<<<<<<
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_8 >= 2) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 511, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    if (likely(__pyx_t_1 != Py_None)) {
      PyObject* sequence = __pyx_t_1;
      #if !CYTHON_COMPILING_IN_PYPY
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 511, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 511, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 511, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 511, __pyx_L1_error)
    }
    __pyx_t_10 = __Pyx_PyInt_As_unsigned_int(__pyx_t_9); if (unlikely((__pyx_t_10 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_reads_filepath, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_v_readtype_index = __pyx_t_10;

    /* "_emirge_amplicon.pyx":513
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present             # <<<<<<<<<<<<<<
 *             continue
 *         read_index = 0
 */
    __pyx_t_11 = (__pyx_v_reads_filepath == Py_None);
    __pyx_t_12 = (__pyx_t_11 != 0);
    if (__pyx_t_12) {

      /* "_emirge_amplicon.pyx":514
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 *             continue             # <<<<<<<<<<<<<<
 *         read_index = 0
 *         ks = pykseq.Kseq(reads_filepath)
 */
      goto __pyx_L3_continue;

      /* "_emirge_amplicon.pyx":513
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present             # <<<<<<<<<<<<<<
 *             continue
 *         read_index = 0
 */
    }

    /* "_emirge_amplicon.pyx":515
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 *             continue
 *         read_index = 0             # <<<<<<<<<<<<<<
 *         ks = pykseq.Kseq(reads_filepath)
 *         while 1:
 */
    __pyx_v_read_index = 0;

    /* "_emirge_amplicon.pyx":516
 *             continue
 *         read_index = 0
 *         ks = pykseq.Kseq(reads_filepath)             # <<<<<<<<<<<<<<
 *         while 1:
 *             ks_p = ks.c_read_sequence()
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_reads_filepath);
    __Pyx_GIVEREF(__pyx_v_reads_filepath);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reads_filepath);
    __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6pykseq_Kseq), __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ks, ((struct __pyx_obj_6pykseq_Kseq *)__pyx_t_9));
    __pyx_t_9 = 0;

    /* "_emirge_amplicon.pyx":517
 *         read_index = 0
 *         ks = pykseq.Kseq(reads_filepath)
 *         while 1:             # <<<<<<<<<<<<<<
 *             ks_p = ks.c_read_sequence()
 *             if ks_p == NULL:
 */
    while (1) {

      /* "_emirge_amplicon.pyx":518
 *         ks = pykseq.Kseq(reads_filepath)
 *         while 1:
 *             ks_p = ks.c_read_sequence()             # <<<<<<<<<<<<<<
 *             if ks_p == NULL:
 *                 break
 */
      __pyx_v_ks_p = ((struct __pyx_vtabstruct_6pykseq_Kseq *)__pyx_v_ks->__pyx_vtab)->c_read_sequence(__pyx_v_ks);

      /* "_emirge_amplicon.pyx":519
 *         while 1:
 *             ks_p = ks.c_read_sequence()
 *             if ks_p == NULL:             # <<<<<<<<<<<<<<
 *                 break
 *             else:
 */
      __pyx_t_12 = ((__pyx_v_ks_p == NULL) != 0);
      if (__pyx_t_12) {

        /* "_emirge_amplicon.pyx":520
 *             ks_p = ks.c_read_sequence()
 *             if ks_p == NULL:
 *                 break             # <<<<<<<<<<<<<<
 *             else:
 *                 # read_index = atoi(ks_p.name.s)
 */
        goto __pyx_L7_break;

        /* "_emirge_amplicon.pyx":519
 *         while 1:
 *             ks_p = ks.c_read_sequence()
 *             if ks_p == NULL:             # <<<<<<<<<<<<<<
 *                 break
 *             else:
 */
      }

      /* "_emirge_amplicon.pyx":523
 *             else:
 *                 # read_index = atoi(ks_p.name.s)
 *                 readlengths[read_index] = ks_p.seq.l             # <<<<<<<<<<<<<<
 *                 for i in range(0, ks_p.seq.l):
 *                     reads[read_index, readtype_index, i] = base_alpha2int(ks_p.seq.s[i])
 */
      /*else*/ {
        __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_ks_p->seq.l); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 523, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_readlengths), __pyx_v_read_index, __pyx_t_9, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 1) < 0)) __PYX_ERR(0, 523, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "_emirge_amplicon.pyx":524
 *                 # read_index = atoi(ks_p.name.s)
 *                 readlengths[read_index] = ks_p.seq.l
 *                 for i in range(0, ks_p.seq.l):             # <<<<<<<<<<<<<<
 *                     reads[read_index, readtype_index, i] = base_alpha2int(ks_p.seq.s[i])
 *                     quals[read_index, readtype_index, i] = ks_p.qual.s[i] - ascii_offset
 */
        __pyx_t_5 = __pyx_v_ks_p->seq.l;
        for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_5; __pyx_t_10+=1) {
          __pyx_v_i = __pyx_t_10;

          /* "_emirge_amplicon.pyx":525
 *                 readlengths[read_index] = ks_p.seq.l
 *                 for i in range(0, ks_p.seq.l):
 *                     reads[read_index, readtype_index, i] = base_alpha2int(ks_p.seq.s[i])             # <<<<<<<<<<<<<<
 *                     quals[read_index, readtype_index, i] = ks_p.qual.s[i] - ascii_offset
 *                 read_index += 1
 */
          __pyx_t_13 = __pyx_v_read_index;
          __pyx_t_14 = __pyx_v_readtype_index;
          __pyx_t_15 = __pyx_v_i;
          __pyx_t_16 = -1;
          if (unlikely(__pyx_t_13 >= (size_t)__pyx_pybuffernd_reads.diminfo[0].shape)) __pyx_t_16 = 0;
          if (unlikely(__pyx_t_14 >= (size_t)__pyx_pybuffernd_reads.diminfo[1].shape)) __pyx_t_16 = 1;
          if (unlikely(__pyx_t_15 >= (size_t)__pyx_pybuffernd_reads.diminfo[2].shape)) __pyx_t_16 = 2;
          if (unlikely(__pyx_t_16 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_16);
            __PYX_ERR(0, 525, __pyx_L1_error)
          }
          *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_reads.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_reads.diminfo[1].strides, __pyx_t_15, __pyx_pybuffernd_reads.diminfo[2].strides) = __pyx_f_16_emirge_amplicon_base_alpha2int((__pyx_v_ks_p->seq.s[__pyx_v_i]));

          /* "_emirge_amplicon.pyx":526
 *                 for i in range(0, ks_p.seq.l):
 *                     reads[read_index, readtype_index, i] = base_alpha2int(ks_p.seq.s[i])
 *                     quals[read_index, readtype_index, i] = ks_p.qual.s[i] - ascii_offset             # <<<<<<<<<<<<<<
 *                 read_index += 1
 * 
 */
          __pyx_t_17 = __pyx_v_read_index;
          __pyx_t_18 = __pyx_v_readtype_index;
          __pyx_t_19 = __pyx_v_i;
          __pyx_t_16 = -1;
          if (unlikely(__pyx_t_17 >= (size_t)__pyx_pybuffernd_quals.diminfo[0].shape)) __pyx_t_16 = 0;
          if (unlikely(__pyx_t_18 >= (size_t)__pyx_pybuffernd_quals.diminfo[1].shape)) __pyx_t_16 = 1;
          if (unlikely(__pyx_t_19 >= (size_t)__pyx_pybuffernd_quals.diminfo[2].shape)) __pyx_t_16 = 2;
          if (unlikely(__pyx_t_16 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_16);
            __PYX_ERR(0, 526, __pyx_L1_error)
          }
          *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_quals.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_quals.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_quals.diminfo[1].strides, __pyx_t_19, __pyx_pybuffernd_quals.diminfo[2].strides) = ((__pyx_v_ks_p->qual.s[__pyx_v_i]) - __pyx_v_ascii_offset);
        }

        /* "_emirge_amplicon.pyx":527
 *                     reads[read_index, readtype_index, i] = base_alpha2int(ks_p.seq.s[i])
 *                     quals[read_index, readtype_index, i] = ks_p.qual.s[i] - ascii_offset
 *                 read_index += 1             # <<<<<<<<<<<<<<
 * 
 *     return
 */
        __pyx_v_read_index = (__pyx_v_read_index + 1);
      }
    }
    __pyx_L7_break:;

    /* "_emirge_amplicon.pyx":511
 * 
 *     # first do /1 reads, then do /2 reads if present
 *     for reads_filepath, readtype_index in [(em.reads1_filepath, 0),             # <<<<<<<<<<<<<<
 *                                            (em.reads2_filepath, 1)]:
 *         if reads_filepath is None:  # should only happen if no reads2_filepath present
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":529
 *                 read_index += 1
 * 
 *     return             # <<<<<<<<<<<<<<
 * 
 * def process_bamfile(em, int ascii_offset):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":490
 * 
 * 
 * def populate_reads_arrays(em):             # <<<<<<<<<<<<<<
 *     """
 *     2.  populates:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_readlengths.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon.populate_reads_arrays", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quals.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_readlengths.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_reads);
  __Pyx_XDECREF((PyObject *)__pyx_v_quals);
  __Pyx_XDECREF((PyObject *)__pyx_v_readlengths);
  __Pyx_XDECREF((PyObject *)__pyx_v_ks);
  __Pyx_XDECREF(__pyx_v_reads_filepath);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":531
 *     return
 * 
 * def process_bamfile(em, int ascii_offset):             # <<<<<<<<<<<<<<
 *     """
 *     read in bamfile and populate:
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_11process_bamfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_16_emirge_amplicon_10process_bamfile[] = "\n    read in bamfile and populate:\n       bamfile_data    # [seq_i, read_i, pair_i, rlen, pos, is_reverse]\n       sequence_name2sequence_i if new entries are here that we haven't seen in previous rounds.\n\n    assume read name is an integer == read index.\n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_11process_bamfile = {"process_bamfile", (PyCFunction)__pyx_pw_16_emirge_amplicon_11process_bamfile, METH_VARARGS|METH_KEYWORDS, __pyx_doc_16_emirge_amplicon_10process_bamfile};
static PyObject *__pyx_pw_16_emirge_amplicon_11process_bamfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_em = 0;
  CYTHON_UNUSED int __pyx_v_ascii_offset;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("process_bamfile (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_em,&__pyx_n_s_ascii_offset,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_em)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ascii_offset)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("process_bamfile", 1, 2, 2, 1); __PYX_ERR(0, 531, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "process_bamfile") < 0)) __PYX_ERR(0, 531, __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_em = values[0];
    __pyx_v_ascii_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_ascii_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 531, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("process_bamfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 531, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_emirge_amplicon.process_bamfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_16_emirge_amplicon_10process_bamfile(__pyx_self, __pyx_v_em, __pyx_v_ascii_offset);

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

static PyObject *__pyx_pf_16_emirge_amplicon_10process_bamfile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em, CYTHON_UNUSED int __pyx_v_ascii_offset) {
  PyObject *__pyx_v_mode = NULL;
  PyObject *__pyx_v_bamfile = NULL;
  PyObject *__pyx_v_sequence_name2sequence_i = 0;
  PyObject *__pyx_v_sequence_i2sequence_name = 0;
  PyArrayObject *__pyx_v_bamfile_data = 0;
  int __pyx_v_i;
  unsigned int __pyx_v_alignedread_i;
  unsigned int __pyx_v_tid;
  unsigned int __pyx_v_read_i;
  unsigned int __pyx_v_seq_i;
  unsigned int __pyx_v_new_seq_i;
  char *__pyx_v_qname;
  unsigned int __pyx_v_n_reads_mapped;
  PyArrayObject *__pyx_v_reads_mapped = 0;
  PyArrayObject *__pyx_v_base_coverage = 0;
  CYTHON_UNUSED PyObject *__pyx_v_samfile_references = NULL;
  PyObject *__pyx_v_samfile_lengths = NULL;
  PyArrayObject *__pyx_v_tid2seq_i = 0;
  PyArrayObject *__pyx_v_tid_mapped = 0;
  CYTHON_UNUSED PyObject *__pyx_v_t_check = NULL;
  PyObject *__pyx_v_alignedread = NULL;
  PyObject *__pyx_v_refname = NULL;
  PyArrayObject *__pyx_v_coverage = 0;
  PyObject *__pyx_v_base_coverages = 0;
  PyObject *__pyx_v_max_length = NULL;
  PyArrayObject *__pyx_v_base_coverages_2d = 0;
  PyObject *__pyx_v_qname_temp = NULL;
  int __pyx_v_n_reads_total;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bamfile_data;
  __Pyx_Buffer __pyx_pybuffer_bamfile_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_base_coverage;
  __Pyx_Buffer __pyx_pybuffer_base_coverage;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_base_coverages_2d;
  __Pyx_Buffer __pyx_pybuffer_base_coverages_2d;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_coverage;
  __Pyx_Buffer __pyx_pybuffer_coverage;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_reads_mapped;
  __Pyx_Buffer __pyx_pybuffer_reads_mapped;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tid2seq_i;
  __Pyx_Buffer __pyx_pybuffer_tid2seq_i;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tid_mapped;
  __Pyx_Buffer __pyx_pybuffer_tid_mapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyArrayObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyArrayObject *__pyx_t_14 = NULL;
  PyArrayObject *__pyx_t_15 = NULL;
  PyObject *(*__pyx_t_16)(PyObject *);
  unsigned int __pyx_t_17;
  size_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  unsigned int __pyx_t_23;
  size_t __pyx_t_24;
  PyArrayObject *__pyx_t_25 = NULL;
  PyArrayObject *__pyx_t_26 = NULL;
  PyArrayObject *__pyx_t_27 = NULL;
  npy_intp __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  int __pyx_t_30;
  size_t __pyx_t_31;
  Py_ssize_t __pyx_t_32;
  char *__pyx_t_33;
  size_t __pyx_t_34;
  size_t __pyx_t_35;
  long __pyx_t_36;
  long __pyx_t_37;
  size_t __pyx_t_38;
  Py_ssize_t __pyx_t_39;
  size_t __pyx_t_40;
  Py_ssize_t __pyx_t_41;
  size_t __pyx_t_42;
  Py_ssize_t __pyx_t_43;
  __pyx_t_5numpy_uint32_t __pyx_t_44;
  size_t __pyx_t_45;
  Py_ssize_t __pyx_t_46;
  size_t __pyx_t_47;
  Py_ssize_t __pyx_t_48;
  size_t __pyx_t_49;
  Py_ssize_t __pyx_t_50;
  size_t __pyx_t_51;
  Py_ssize_t __pyx_t_52;
  size_t __pyx_t_53;
  Py_ssize_t __pyx_t_54;
  Py_ssize_t __pyx_t_55;
  Py_ssize_t __pyx_t_56;
  int __pyx_t_57;
  __Pyx_RefNannySetupContext("process_bamfile", 0);
  __pyx_pybuffer_bamfile_data.pybuffer.buf = NULL;
  __pyx_pybuffer_bamfile_data.refcount = 0;
  __pyx_pybuffernd_bamfile_data.data = NULL;
  __pyx_pybuffernd_bamfile_data.rcbuffer = &__pyx_pybuffer_bamfile_data;
  __pyx_pybuffer_reads_mapped.pybuffer.buf = NULL;
  __pyx_pybuffer_reads_mapped.refcount = 0;
  __pyx_pybuffernd_reads_mapped.data = NULL;
  __pyx_pybuffernd_reads_mapped.rcbuffer = &__pyx_pybuffer_reads_mapped;
  __pyx_pybuffer_base_coverage.pybuffer.buf = NULL;
  __pyx_pybuffer_base_coverage.refcount = 0;
  __pyx_pybuffernd_base_coverage.data = NULL;
  __pyx_pybuffernd_base_coverage.rcbuffer = &__pyx_pybuffer_base_coverage;
  __pyx_pybuffer_tid2seq_i.pybuffer.buf = NULL;
  __pyx_pybuffer_tid2seq_i.refcount = 0;
  __pyx_pybuffernd_tid2seq_i.data = NULL;
  __pyx_pybuffernd_tid2seq_i.rcbuffer = &__pyx_pybuffer_tid2seq_i;
  __pyx_pybuffer_tid_mapped.pybuffer.buf = NULL;
  __pyx_pybuffer_tid_mapped.refcount = 0;
  __pyx_pybuffernd_tid_mapped.data = NULL;
  __pyx_pybuffernd_tid_mapped.rcbuffer = &__pyx_pybuffer_tid_mapped;
  __pyx_pybuffer_coverage.pybuffer.buf = NULL;
  __pyx_pybuffer_coverage.refcount = 0;
  __pyx_pybuffernd_coverage.data = NULL;
  __pyx_pybuffernd_coverage.rcbuffer = &__pyx_pybuffer_coverage;
  __pyx_pybuffer_base_coverages_2d.pybuffer.buf = NULL;
  __pyx_pybuffer_base_coverages_2d.refcount = 0;
  __pyx_pybuffernd_base_coverages_2d.data = NULL;
  __pyx_pybuffernd_base_coverages_2d.rcbuffer = &__pyx_pybuffer_base_coverages_2d;

  /* "_emirge_amplicon.pyx":543
 *     # not to pipe it to samtools, even though CPU load (always < 100%
 *     # ) doesn't explain this)
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "_emirge_amplicon.pyx":544
 *     # ) doesn't explain this)
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"             # <<<<<<<<<<<<<<
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"
 */
    __Pyx_INCREF(__pyx_n_s_rb);
    __pyx_v_mode = __pyx_n_s_rb;

    /* "_emirge_amplicon.pyx":543
 *     # not to pipe it to samtools, even though CPU load (always < 100%
 *     # ) doesn't explain this)
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
    goto __pyx_L3;
  }

  /* "_emirge_amplicon.pyx":545
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "_emirge_amplicon.pyx":546
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"             # <<<<<<<<<<<<<<
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 *     # TODO: any Cython tricks with string-->int dictionaries (looks like maybe in pxd)
 */
    __Pyx_INCREF(__pyx_n_s_r);
    __pyx_v_mode = __pyx_n_s_r;

    /* "_emirge_amplicon.pyx":545
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  }
  __pyx_L3:;

  /* "_emirge_amplicon.pyx":547
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)             # <<<<<<<<<<<<<<
 *     # TODO: any Cython tricks with string-->int dictionaries (looks like maybe in pxd)
 *     cdef dict sequence_name2sequence_i = em.sequence_name2sequence_i
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pysam); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Samfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(!__pyx_v_mode)) { __Pyx_RaiseUnboundLocalError("mode"); __PYX_ERR(0, 547, __pyx_L1_error) }
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 547, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_2);
    __Pyx_INCREF(__pyx_v_mode);
    __Pyx_GIVEREF(__pyx_v_mode);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_mode);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_bamfile = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":549
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 *     # TODO: any Cython tricks with string-->int dictionaries (looks like maybe in pxd)
 *     cdef dict sequence_name2sequence_i = em.sequence_name2sequence_i             # <<<<<<<<<<<<<<
 *     cdef list sequence_i2sequence_name = em.sequence_i2sequence_name
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_sequence_name2sequence_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 549, __pyx_L1_error)
  __pyx_v_sequence_name2sequence_i = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":550
 *     # TODO: any Cython tricks with string-->int dictionaries (looks like maybe in pxd)
 *     cdef dict sequence_name2sequence_i = em.sequence_name2sequence_i
 *     cdef list sequence_i2sequence_name = em.sequence_i2sequence_name             # <<<<<<<<<<<<<<
 * 
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_sequence_i2sequence_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 550, __pyx_L1_error)
  __pyx_v_sequence_i2sequence_name = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":553
 * 
 *     cdef np.ndarray[np.uint32_t, ndim=2] bamfile_data
 *     bamfile_data = np.empty((em.n_alignments, 6), dtype=np.uint32)             # <<<<<<<<<<<<<<
 * 
 *     cdef int i                          # generic counter
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_n_alignments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_6);
  __Pyx_GIVEREF(__pyx_int_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_6);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_uint32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 553, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_bamfile_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_bamfile_data.diminfo[0].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bamfile_data.diminfo[0].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bamfile_data.diminfo[1].strides = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bamfile_data.diminfo[1].shape = __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 553, __pyx_L1_error)
  }
  __pyx_t_8 = 0;
  __pyx_v_bamfile_data = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "_emirge_amplicon.pyx":569
 *     cdef char *qname
 *     cdef bint is_reverse
 *     cdef unsigned int n_reads_mapped = 0  # num. of single reads or pairs             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_mapped = np.zeros(em.n_reads, dtype=np.uint8) # mapped this round = 1
 *     cdef np.ndarray[np.uint32_t, ndim=1] base_coverage # single base coverage
 */
  __pyx_v_n_reads_mapped = 0;

  /* "_emirge_amplicon.pyx":570
 *     cdef bint is_reverse
 *     cdef unsigned int n_reads_mapped = 0  # num. of single reads or pairs
 *     cdef np.ndarray[np.uint8_t, ndim=1] reads_mapped = np.zeros(em.n_reads, dtype=np.uint8) # mapped this round = 1             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint32_t, ndim=1] base_coverage # single base coverage
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_n_reads); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_uint8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 570, __pyx_L1_error)
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_reads_mapped = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 570, __pyx_L1_error)
    } else {__pyx_pybuffernd_reads_mapped.diminfo[0].strides = __pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_reads_mapped.diminfo[0].shape = __pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_12 = 0;
  __pyx_v_reads_mapped = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":573
 *     cdef np.ndarray[np.uint32_t, ndim=1] base_coverage # single base coverage
 * 
 *     samfile_references = np.array(bamfile.references)  # faster to slice numpy array             # <<<<<<<<<<<<<<
 *     samfile_lengths    = np.array(bamfile.lengths)  # faster to slice numpy array
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_references); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_samfile_references = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":574
 * 
 *     samfile_references = np.array(bamfile.references)  # faster to slice numpy array
 *     samfile_lengths    = np.array(bamfile.lengths)  # faster to slice numpy array             # <<<<<<<<<<<<<<
 * 
 *     # go through header here and create mapping between reference tid
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_lengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_1};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_1};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_samfile_lengths = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":580
 *     # seen, map name to seq_i here once, rather than doing costly
 *     # dictionary lookup for each and every alignedread
 *     cdef np.ndarray[np.uint32_t, ndim=1] tid2seq_i = np.zeros(len(bamfile.references), dtype=np.uint32)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint8_t, ndim=1] tid_mapped = np.zeros(len(bamfile.references), dtype=np.uint8)
 *     t_check = time()
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_13 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_uint32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 580, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_tid2seq_i = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 580, __pyx_L1_error)
    } else {__pyx_pybuffernd_tid2seq_i.diminfo[0].strides = __pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tid2seq_i.diminfo[0].shape = __pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_14 = 0;
  __pyx_v_tid2seq_i = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "_emirge_amplicon.pyx":581
 *     # dictionary lookup for each and every alignedread
 *     cdef np.ndarray[np.uint32_t, ndim=1] tid2seq_i = np.zeros(len(bamfile.references), dtype=np.uint32)
 *     cdef np.ndarray[np.uint8_t, ndim=1] tid_mapped = np.zeros(len(bamfile.references), dtype=np.uint8)             # <<<<<<<<<<<<<<
 *     t_check = time()
 *     for alignedread in bamfile:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_references); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_13 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_uint8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 581, __pyx_L1_error)
  __pyx_t_15 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_tid_mapped = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 581, __pyx_L1_error)
    } else {__pyx_pybuffernd_tid_mapped.diminfo[0].strides = __pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tid_mapped.diminfo[0].shape = __pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_15 = 0;
  __pyx_v_tid_mapped = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":582
 *     cdef np.ndarray[np.uint32_t, ndim=1] tid2seq_i = np.zeros(len(bamfile.references), dtype=np.uint32)
 *     cdef np.ndarray[np.uint8_t, ndim=1] tid_mapped = np.zeros(len(bamfile.references), dtype=np.uint8)
 *     t_check = time()             # <<<<<<<<<<<<<<
 *     for alignedread in bamfile:
 *         tid_mapped[alignedread.tid] = 1
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_7) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 582, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 582, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_t_check = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":583
 *     cdef np.ndarray[np.uint8_t, ndim=1] tid_mapped = np.zeros(len(bamfile.references), dtype=np.uint8)
 *     t_check = time()
 *     for alignedread in bamfile:             # <<<<<<<<<<<<<<
 *         tid_mapped[alignedread.tid] = 1
 *     # print >> sys.stderr, "DEBUG: first pass bamfile time: %s"%(timedelta(seconds = time()-t_check))
 */
  if (likely(PyList_CheckExact(__pyx_v_bamfile)) || PyTuple_CheckExact(__pyx_v_bamfile)) {
    __pyx_t_1 = __pyx_v_bamfile; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0;
    __pyx_t_16 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_bamfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_16 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 583, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_16)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 583, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 583, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 583, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 583, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_16(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 583, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_alignedread, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "_emirge_amplicon.pyx":584
 *     t_check = time()
 *     for alignedread in bamfile:
 *         tid_mapped[alignedread.tid] = 1             # <<<<<<<<<<<<<<
 *     # print >> sys.stderr, "DEBUG: first pass bamfile time: %s"%(timedelta(seconds = time()-t_check))
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_tid_mapped), __pyx_t_5, __pyx_int_1) < 0)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "_emirge_amplicon.pyx":583
 *     cdef np.ndarray[np.uint8_t, ndim=1] tid_mapped = np.zeros(len(bamfile.references), dtype=np.uint8)
 *     t_check = time()
 *     for alignedread in bamfile:             # <<<<<<<<<<<<<<
 *         tid_mapped[alignedread.tid] = 1
 *     # print >> sys.stderr, "DEBUG: first pass bamfile time: %s"%(timedelta(seconds = time()-t_check))
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":587
 *     # print >> sys.stderr, "DEBUG: first pass bamfile time: %s"%(timedelta(seconds = time()-t_check))
 * 
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)  # reopen file to reset.  seek(0) has problems?             # <<<<<<<<<<<<<<
 * 
 *     new_seq_i = len(sequence_i2sequence_name)
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pysam); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Samfile); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (unlikely(!__pyx_v_mode)) { __Pyx_RaiseUnboundLocalError("mode"); __PYX_ERR(0, 587, __pyx_L1_error) }
  __pyx_t_2 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_7)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 587, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_t_5);
    __Pyx_INCREF(__pyx_v_mode);
    __Pyx_GIVEREF(__pyx_v_mode);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_v_mode);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_bamfile, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":589
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)  # reopen file to reset.  seek(0) has problems?
 * 
 *     new_seq_i = len(sequence_i2sequence_name)             # <<<<<<<<<<<<<<
 *     for tid, refname in enumerate(bamfile.references):
 *         # assert bamfile.getrname(tid) == refname # this is true
 */
  if (unlikely(__pyx_v_sequence_i2sequence_name == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 589, __pyx_L1_error)
  }
  __pyx_t_13 = PyList_GET_SIZE(__pyx_v_sequence_i2sequence_name); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 589, __pyx_L1_error)
  __pyx_v_new_seq_i = __pyx_t_13;

  /* "_emirge_amplicon.pyx":590
 * 
 *     new_seq_i = len(sequence_i2sequence_name)
 *     for tid, refname in enumerate(bamfile.references):             # <<<<<<<<<<<<<<
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:
 */
  __pyx_t_17 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_references); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_13 = 0;
    __pyx_t_16 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 590, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_16 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 590, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_16)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 590, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 590, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_16(__pyx_t_7);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 590, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_refname, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_v_tid = __pyx_t_17;
    __pyx_t_17 = (__pyx_t_17 + 1);

    /* "_emirge_amplicon.pyx":592
 *     for tid, refname in enumerate(bamfile.references):
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:             # <<<<<<<<<<<<<<
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before
 *                 seq_i = new_seq_i
 */
    __pyx_t_18 = __pyx_v_tid;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_18 >= (size_t)__pyx_pybuffernd_tid_mapped.diminfo[0].shape)) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 592, __pyx_L1_error)
    }
    __pyx_t_3 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_tid_mapped.diminfo[0].strides)) == 1) != 0);
    if (__pyx_t_3) {

      /* "_emirge_amplicon.pyx":593
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before             # <<<<<<<<<<<<<<
 *                 seq_i = new_seq_i
 *                 new_seq_i = new_seq_i + 1
 */
      if (unlikely(__pyx_v_sequence_name2sequence_i == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "has_key");
        __PYX_ERR(0, 593, __pyx_L1_error)
      }
      __pyx_t_3 = PyDict_Contains(__pyx_v_sequence_name2sequence_i, __pyx_v_refname); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 593, __pyx_L1_error)
      __pyx_t_19 = ((!(__pyx_t_3 != 0)) != 0);
      if (__pyx_t_19) {

        /* "_emirge_amplicon.pyx":594
 *         if tid_mapped[tid] == 1:
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before
 *                 seq_i = new_seq_i             # <<<<<<<<<<<<<<
 *                 new_seq_i = new_seq_i + 1
 *                 sequence_name2sequence_i[refname] =  seq_i
 */
        __pyx_v_seq_i = __pyx_v_new_seq_i;

        /* "_emirge_amplicon.pyx":595
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before
 *                 seq_i = new_seq_i
 *                 new_seq_i = new_seq_i + 1             # <<<<<<<<<<<<<<
 *                 sequence_name2sequence_i[refname] =  seq_i
 *                 sequence_i2sequence_name.append(refname)
 */
        __pyx_v_new_seq_i = (__pyx_v_new_seq_i + 1);

        /* "_emirge_amplicon.pyx":596
 *                 seq_i = new_seq_i
 *                 new_seq_i = new_seq_i + 1
 *                 sequence_name2sequence_i[refname] =  seq_i             # <<<<<<<<<<<<<<
 *                 sequence_i2sequence_name.append(refname)
 *                 em.base_coverages.append(np.zeros(samfile_lengths[tid], dtype=np.uint32))
 */
        __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_seq_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_sequence_name2sequence_i == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 596, __pyx_L1_error)
        }
        if (unlikely(PyDict_SetItem(__pyx_v_sequence_name2sequence_i, __pyx_v_refname, __pyx_t_1) < 0)) __PYX_ERR(0, 596, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "_emirge_amplicon.pyx":597
 *                 new_seq_i = new_seq_i + 1
 *                 sequence_name2sequence_i[refname] =  seq_i
 *                 sequence_i2sequence_name.append(refname)             # <<<<<<<<<<<<<<
 *                 em.base_coverages.append(np.zeros(samfile_lengths[tid], dtype=np.uint32))
 *             else:
 */
        if (unlikely(__pyx_v_sequence_i2sequence_name == Py_None)) {
          PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
          __PYX_ERR(0, 597, __pyx_L1_error)
        }
        __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_sequence_i2sequence_name, __pyx_v_refname); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 597, __pyx_L1_error)

        /* "_emirge_amplicon.pyx":598
 *                 sequence_name2sequence_i[refname] =  seq_i
 *                 sequence_i2sequence_name.append(refname)
 *                 em.base_coverages.append(np.zeros(samfile_lengths[tid], dtype=np.uint32))             # <<<<<<<<<<<<<<
 *             else:
 *                 seq_i = sequence_name2sequence_i[refname]
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_base_coverages); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_samfile_lengths, __pyx_v_tid, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_21 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_21);
        __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_uint32); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_22);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
        if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_22) < 0) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        __pyx_t_22 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_22);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_20 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_t_22); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;

        /* "_emirge_amplicon.pyx":593
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before             # <<<<<<<<<<<<<<
 *                 seq_i = new_seq_i
 *                 new_seq_i = new_seq_i + 1
 */
        goto __pyx_L9;
      }

      /* "_emirge_amplicon.pyx":600
 *                 em.base_coverages.append(np.zeros(samfile_lengths[tid], dtype=np.uint32))
 *             else:
 *                 seq_i = sequence_name2sequence_i[refname]             # <<<<<<<<<<<<<<
 *             tid2seq_i[tid] = seq_i
 * 
 */
      /*else*/ {
        if (unlikely(__pyx_v_sequence_name2sequence_i == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 600, __pyx_L1_error)
        }
        __pyx_t_22 = __Pyx_PyDict_GetItem(__pyx_v_sequence_name2sequence_i, __pyx_v_refname); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 600, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_22);
        __pyx_t_23 = __Pyx_PyInt_As_unsigned_int(__pyx_t_22); if (unlikely((__pyx_t_23 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 600, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
        __pyx_v_seq_i = __pyx_t_23;
      }
      __pyx_L9:;

      /* "_emirge_amplicon.pyx":601
 *             else:
 *                 seq_i = sequence_name2sequence_i[refname]
 *             tid2seq_i[tid] = seq_i             # <<<<<<<<<<<<<<
 * 
 *     # reset this here to be size of n_sequences
 */
      __pyx_t_24 = __pyx_v_tid;
      __pyx_t_6 = -1;
      if (unlikely(__pyx_t_24 >= (size_t)__pyx_pybuffernd_tid2seq_i.diminfo[0].shape)) __pyx_t_6 = 0;
      if (unlikely(__pyx_t_6 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_6);
        __PYX_ERR(0, 601, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_tid2seq_i.diminfo[0].strides) = __pyx_v_seq_i;

      /* "_emirge_amplicon.pyx":592
 *     for tid, refname in enumerate(bamfile.references):
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:             # <<<<<<<<<<<<<<
 *             if not sequence_name2sequence_i.has_key(refname):  # new sequence we haven't seen before
 *                 seq_i = new_seq_i
 */
    }

    /* "_emirge_amplicon.pyx":590
 * 
 *     new_seq_i = len(sequence_i2sequence_name)
 *     for tid, refname in enumerate(bamfile.references):             # <<<<<<<<<<<<<<
 *         # assert bamfile.getrname(tid) == refname # this is true
 *         if tid_mapped[tid] == 1:
 */
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "_emirge_amplicon.pyx":604
 * 
 *     # reset this here to be size of n_sequences
 *     em.coverage = np.zeros(len(sequence_name2sequence_i), dtype=np.uint32)             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint32_t, ndim=1] coverage = em.coverage
 * 
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_22);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(__pyx_v_sequence_name2sequence_i == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 604, __pyx_L1_error)
  }
  __pyx_t_13 = PyDict_Size(__pyx_v_sequence_name2sequence_i); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 604, __pyx_L1_error)
  __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_uint32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_em, __pyx_n_s_coverage, __pyx_t_2) < 0) __PYX_ERR(0, 604, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":605
 *     # reset this here to be size of n_sequences
 *     em.coverage = np.zeros(len(sequence_name2sequence_i), dtype=np.uint32)
 *     cdef np.ndarray[np.uint32_t, ndim=1] coverage = em.coverage             # <<<<<<<<<<<<<<
 * 
 *     # and now keep temporary base_coverages in numpy array for speed below.
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_coverage); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 605, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 605, __pyx_L1_error)
  __pyx_t_25 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_t_25, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_coverage = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_coverage.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 605, __pyx_L1_error)
    } else {__pyx_pybuffernd_coverage.diminfo[0].strides = __pyx_pybuffernd_coverage.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_coverage.diminfo[0].shape = __pyx_pybuffernd_coverage.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_25 = 0;
  __pyx_v_coverage = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":608
 * 
 *     # and now keep temporary base_coverages in numpy array for speed below.
 *     cdef list base_coverages = em.base_coverages  # list of arrays             # <<<<<<<<<<<<<<
 *     max_length = max([base_coverage.shape[0] for base_coverage in base_coverages])
 *     cdef np.ndarray[np.uint32_t, ndim=2] base_coverages_2d = np.zeros((len(base_coverages), max_length), dtype=np.uint32)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_base_coverages); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 608, __pyx_L1_error)
  __pyx_v_base_coverages = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":609
 *     # and now keep temporary base_coverages in numpy array for speed below.
 *     cdef list base_coverages = em.base_coverages  # list of arrays
 *     max_length = max([base_coverage.shape[0] for base_coverage in base_coverages])             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[np.uint32_t, ndim=2] base_coverages_2d = np.zeros((len(base_coverages), max_length), dtype=np.uint32)
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(__pyx_v_base_coverages == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 609, __pyx_L1_error)
  }
  __pyx_t_7 = __pyx_v_base_coverages; __Pyx_INCREF(__pyx_t_7); __pyx_t_13 = 0;
  for (;;) {
    if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_7)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 609, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 609, __pyx_L1_error)
    __pyx_t_26 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_v_base_coverage, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_base_coverage.diminfo[0].strides = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_base_coverage.diminfo[0].shape = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 609, __pyx_L1_error)
    }
    __pyx_t_26 = 0;
    __Pyx_XDECREF_SET(__pyx_v_base_coverage, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_From_Py_intptr_t((__pyx_v_base_coverage->dimensions[0])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_max_length = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":610
 *     cdef list base_coverages = em.base_coverages  # list of arrays
 *     max_length = max([base_coverage.shape[0] for base_coverage in base_coverages])
 *     cdef np.ndarray[np.uint32_t, ndim=2] base_coverages_2d = np.zeros((len(base_coverages), max_length), dtype=np.uint32)             # <<<<<<<<<<<<<<
 * 
 *     for seq_i, base_coverage in enumerate(base_coverages):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_v_base_coverages == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 610, __pyx_L1_error)
  }
  __pyx_t_13 = PyList_GET_SIZE(__pyx_v_base_coverages); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 610, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_max_length);
  __Pyx_GIVEREF(__pyx_v_max_length);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_max_length);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_22 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_22);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_uint32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 610, __pyx_L1_error)
  __pyx_t_27 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer, (PyObject*)__pyx_t_27, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_base_coverages_2d = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 610, __pyx_L1_error)
    } else {__pyx_pybuffernd_base_coverages_2d.diminfo[0].strides = __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_base_coverages_2d.diminfo[0].shape = __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_base_coverages_2d.diminfo[1].strides = __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape = __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_27 = 0;
  __pyx_v_base_coverages_2d = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":612
 *     cdef np.ndarray[np.uint32_t, ndim=2] base_coverages_2d = np.zeros((len(base_coverages), max_length), dtype=np.uint32)
 * 
 *     for seq_i, base_coverage in enumerate(base_coverages):             # <<<<<<<<<<<<<<
 *         for i in range(base_coverage.shape[0]):
 *             base_coverages_2d[seq_i, i] = base_coverage[i]
 */
  __pyx_t_17 = 0;
  __pyx_t_4 = __pyx_v_base_coverages; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
  for (;;) {
    if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 612, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 612, __pyx_L1_error)
    __pyx_t_26 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_v_base_coverage, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
      }
      __pyx_pybuffernd_base_coverage.diminfo[0].strides = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_base_coverage.diminfo[0].shape = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 612, __pyx_L1_error)
    }
    __pyx_t_26 = 0;
    __Pyx_XDECREF_SET(__pyx_v_base_coverage, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;
    __pyx_v_seq_i = __pyx_t_17;
    __pyx_t_17 = (__pyx_t_17 + 1);

    /* "_emirge_amplicon.pyx":613
 * 
 *     for seq_i, base_coverage in enumerate(base_coverages):
 *         for i in range(base_coverage.shape[0]):             # <<<<<<<<<<<<<<
 *             base_coverages_2d[seq_i, i] = base_coverage[i]
 * 
 */
    __pyx_t_28 = (__pyx_v_base_coverage->dimensions[0]);
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_28; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "_emirge_amplicon.pyx":614
 *     for seq_i, base_coverage in enumerate(base_coverages):
 *         for i in range(base_coverage.shape[0]):
 *             base_coverages_2d[seq_i, i] = base_coverage[i]             # <<<<<<<<<<<<<<
 * 
 *     alignedread_i = 0
 */
      __pyx_t_29 = __pyx_v_i;
      __pyx_t_30 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_pybuffernd_base_coverage.diminfo[0].shape;
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_base_coverage.diminfo[0].shape)) __pyx_t_30 = 0;
      if (unlikely(__pyx_t_30 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_30);
        __PYX_ERR(0, 614, __pyx_L1_error)
      }
      __pyx_t_31 = __pyx_v_seq_i;
      __pyx_t_32 = __pyx_v_i;
      __pyx_t_30 = -1;
      if (unlikely(__pyx_t_31 >= (size_t)__pyx_pybuffernd_base_coverages_2d.diminfo[0].shape)) __pyx_t_30 = 0;
      if (__pyx_t_32 < 0) {
        __pyx_t_32 += __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape;
        if (unlikely(__pyx_t_32 < 0)) __pyx_t_30 = 1;
      } else if (unlikely(__pyx_t_32 >= __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape)) __pyx_t_30 = 1;
      if (unlikely(__pyx_t_30 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_30);
        __PYX_ERR(0, 614, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_base_coverages_2d.diminfo[0].strides, __pyx_t_32, __pyx_pybuffernd_base_coverages_2d.diminfo[1].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_base_coverage.diminfo[0].strides));
    }

    /* "_emirge_amplicon.pyx":612
 *     cdef np.ndarray[np.uint32_t, ndim=2] base_coverages_2d = np.zeros((len(base_coverages), max_length), dtype=np.uint32)
 * 
 *     for seq_i, base_coverage in enumerate(base_coverages):             # <<<<<<<<<<<<<<
 *         for i in range(base_coverage.shape[0]):
 *             base_coverages_2d[seq_i, i] = base_coverage[i]
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":616
 *             base_coverages_2d[seq_i, i] = base_coverage[i]
 * 
 *     alignedread_i = 0             # <<<<<<<<<<<<<<
 *     for alignedread in bamfile:
 *         #TODO: decide if it's better to assign first to typed variable, or assign directly to bamfile_data
 */
  __pyx_v_alignedread_i = 0;

  /* "_emirge_amplicon.pyx":617
 * 
 *     alignedread_i = 0
 *     for alignedread in bamfile:             # <<<<<<<<<<<<<<
 *         #TODO: decide if it's better to assign first to typed variable, or assign directly to bamfile_data
 *         # tid = alignedread.tid
 */
  if (likely(PyList_CheckExact(__pyx_v_bamfile)) || PyTuple_CheckExact(__pyx_v_bamfile)) {
    __pyx_t_4 = __pyx_v_bamfile; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
    __pyx_t_16 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_bamfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 617, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_16 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 617, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_16)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 617, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 617, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_16(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 617, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_alignedread, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "_emirge_amplicon.pyx":621
 *         # tid = alignedread.tid
 *         # pair_i = alignedread.is_read2
 *         qname_temp = alignedread.qname             # <<<<<<<<<<<<<<
 *         qname = qname_temp      # this extra assignment is necessary to go from python object to char*. (see Cython Language Basics)
 *         # is_reverse = alignedread.is_reverse
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_qname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_qname_temp, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "_emirge_amplicon.pyx":622
 *         # pair_i = alignedread.is_read2
 *         qname_temp = alignedread.qname
 *         qname = qname_temp      # this extra assignment is necessary to go from python object to char*. (see Cython Language Basics)             # <<<<<<<<<<<<<<
 *         # is_reverse = alignedread.is_reverse
 *         # rlen = alignedread.rlen
 */
    __pyx_t_33 = __Pyx_PyObject_AsString(__pyx_v_qname_temp); if (unlikely((!__pyx_t_33) && PyErr_Occurred())) __PYX_ERR(0, 622, __pyx_L1_error)
    __pyx_v_qname = __pyx_t_33;

    /* "_emirge_amplicon.pyx":626
 *         # rlen = alignedread.rlen
 * 
 *         read_i = atoi(qname)             # <<<<<<<<<<<<<<
 *         # read_i = int(qname_temp)
 *         reads_mapped[read_i] = 1
 */
    __pyx_v_read_i = atoi(__pyx_v_qname);

    /* "_emirge_amplicon.pyx":628
 *         read_i = atoi(qname)
 *         # read_i = int(qname_temp)
 *         reads_mapped[read_i] = 1             # <<<<<<<<<<<<<<
 *         seq_i = tid2seq_i[alignedread.tid]
 *         coverage[seq_i] += <unsigned int>alignedread.rlen
 */
    __pyx_t_34 = __pyx_v_read_i;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_34 >= (size_t)__pyx_pybuffernd_reads_mapped.diminfo[0].shape)) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 628, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_reads_mapped.diminfo[0].strides) = 1;

    /* "_emirge_amplicon.pyx":629
 *         # read_i = int(qname_temp)
 *         reads_mapped[read_i] = 1
 *         seq_i = tid2seq_i[alignedread.tid]             # <<<<<<<<<<<<<<
 *         coverage[seq_i] += <unsigned int>alignedread.rlen
 *         # base_coverage = em.base_coverages[seq_i]  # list lookup.  SLOW?
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_tid2seq_i), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_17 = __Pyx_PyInt_As_unsigned_int(__pyx_t_2); if (unlikely((__pyx_t_17 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_seq_i = __pyx_t_17;

    /* "_emirge_amplicon.pyx":630
 *         reads_mapped[read_i] = 1
 *         seq_i = tid2seq_i[alignedread.tid]
 *         coverage[seq_i] += <unsigned int>alignedread.rlen             # <<<<<<<<<<<<<<
 *         # base_coverage = em.base_coverages[seq_i]  # list lookup.  SLOW?
 *         # for i in range(alignedread.pos, alignedread.pos+alignedread.rlen):
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_rlen); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_17 = __Pyx_PyInt_As_unsigned_int(__pyx_t_2); if (unlikely((__pyx_t_17 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 630, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_35 = __pyx_v_seq_i;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_35 >= (size_t)__pyx_pybuffernd_coverage.diminfo[0].shape)) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 630, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_coverage.rcbuffer->pybuffer.buf, __pyx_t_35, __pyx_pybuffernd_coverage.diminfo[0].strides) += ((unsigned int)__pyx_t_17);

    /* "_emirge_amplicon.pyx":634
 *         # for i in range(alignedread.pos, alignedread.pos+alignedread.rlen):
 *         #     base_coverage[i] += 1
 *         for i in range(alignedread.pos, alignedread.pos+alignedread.rlen):             # <<<<<<<<<<<<<<
 *              base_coverages_2d[seq_i, i] += 1    # base_coverage[i] += 1
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_rlen); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_36 = __Pyx_PyInt_As_long(__pyx_t_7); if (unlikely((__pyx_t_36 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_pos); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_37 = __Pyx_PyInt_As_long(__pyx_t_7); if (unlikely((__pyx_t_37 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 634, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    for (__pyx_t_6 = __pyx_t_37; __pyx_t_6 < __pyx_t_36; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "_emirge_amplicon.pyx":635
 *         #     base_coverage[i] += 1
 *         for i in range(alignedread.pos, alignedread.pos+alignedread.rlen):
 *              base_coverages_2d[seq_i, i] += 1    # base_coverage[i] += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_38 = __pyx_v_seq_i;
      __pyx_t_39 = __pyx_v_i;
      __pyx_t_30 = -1;
      if (unlikely(__pyx_t_38 >= (size_t)__pyx_pybuffernd_base_coverages_2d.diminfo[0].shape)) __pyx_t_30 = 0;
      if (__pyx_t_39 < 0) {
        __pyx_t_39 += __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape;
        if (unlikely(__pyx_t_39 < 0)) __pyx_t_30 = 1;
      } else if (unlikely(__pyx_t_39 >= __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape)) __pyx_t_30 = 1;
      if (unlikely(__pyx_t_30 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_30);
        __PYX_ERR(0, 635, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.buf, __pyx_t_38, __pyx_pybuffernd_base_coverages_2d.diminfo[0].strides, __pyx_t_39, __pyx_pybuffernd_base_coverages_2d.diminfo[1].strides) += 1;
    }

    /* "_emirge_amplicon.pyx":638
 * 
 * 
 *         bamfile_data[alignedread_i, 0] = seq_i             # <<<<<<<<<<<<<<
 *         bamfile_data[alignedread_i, 1] = read_i
 *         bamfile_data[alignedread_i, 2] = alignedread.is_read2
 */
    __pyx_t_40 = __pyx_v_alignedread_i;
    __pyx_t_41 = 0;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_40 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_41 < 0) {
      __pyx_t_41 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_41 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_41 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 638, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_40, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_41, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_v_seq_i;

    /* "_emirge_amplicon.pyx":639
 * 
 *         bamfile_data[alignedread_i, 0] = seq_i
 *         bamfile_data[alignedread_i, 1] = read_i             # <<<<<<<<<<<<<<
 *         bamfile_data[alignedread_i, 2] = alignedread.is_read2
 *         bamfile_data[alignedread_i, 3] = alignedread.rlen
 */
    __pyx_t_42 = __pyx_v_alignedread_i;
    __pyx_t_43 = 1;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_42 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_43 < 0) {
      __pyx_t_43 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_43 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_43 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 639, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_42, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_43, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_v_read_i;

    /* "_emirge_amplicon.pyx":640
 *         bamfile_data[alignedread_i, 0] = seq_i
 *         bamfile_data[alignedread_i, 1] = read_i
 *         bamfile_data[alignedread_i, 2] = alignedread.is_read2             # <<<<<<<<<<<<<<
 *         bamfile_data[alignedread_i, 3] = alignedread.rlen
 *         bamfile_data[alignedread_i, 4] = alignedread.pos
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_is_read2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_44 = __Pyx_PyInt_As_npy_uint32(__pyx_t_7); if (unlikely((__pyx_t_44 == ((npy_uint32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_45 = __pyx_v_alignedread_i;
    __pyx_t_46 = 2;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_45 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_46 < 0) {
      __pyx_t_46 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_46 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_46 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 640, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_45, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_46, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_t_44;

    /* "_emirge_amplicon.pyx":641
 *         bamfile_data[alignedread_i, 1] = read_i
 *         bamfile_data[alignedread_i, 2] = alignedread.is_read2
 *         bamfile_data[alignedread_i, 3] = alignedread.rlen             # <<<<<<<<<<<<<<
 *         bamfile_data[alignedread_i, 4] = alignedread.pos
 *         bamfile_data[alignedread_i, 5] = alignedread.is_reverse
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_rlen); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_44 = __Pyx_PyInt_As_npy_uint32(__pyx_t_7); if (unlikely((__pyx_t_44 == ((npy_uint32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 641, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_47 = __pyx_v_alignedread_i;
    __pyx_t_48 = 3;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_47 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_48 < 0) {
      __pyx_t_48 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_48 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_48 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 641, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_47, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_48, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_t_44;

    /* "_emirge_amplicon.pyx":642
 *         bamfile_data[alignedread_i, 2] = alignedread.is_read2
 *         bamfile_data[alignedread_i, 3] = alignedread.rlen
 *         bamfile_data[alignedread_i, 4] = alignedread.pos             # <<<<<<<<<<<<<<
 *         bamfile_data[alignedread_i, 5] = alignedread.is_reverse
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_pos); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_44 = __Pyx_PyInt_As_npy_uint32(__pyx_t_7); if (unlikely((__pyx_t_44 == ((npy_uint32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_49 = __pyx_v_alignedread_i;
    __pyx_t_50 = 4;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_49 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_50 < 0) {
      __pyx_t_50 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_50 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_50 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 642, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_49, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_50, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_t_44;

    /* "_emirge_amplicon.pyx":643
 *         bamfile_data[alignedread_i, 3] = alignedread.rlen
 *         bamfile_data[alignedread_i, 4] = alignedread.pos
 *         bamfile_data[alignedread_i, 5] = alignedread.is_reverse             # <<<<<<<<<<<<<<
 * 
 *         alignedread_i += 1
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignedread, __pyx_n_s_is_reverse); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_44 = __Pyx_PyInt_As_npy_uint32(__pyx_t_7); if (unlikely((__pyx_t_44 == ((npy_uint32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 643, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_51 = __pyx_v_alignedread_i;
    __pyx_t_52 = 5;
    __pyx_t_6 = -1;
    if (unlikely(__pyx_t_51 >= (size_t)__pyx_pybuffernd_bamfile_data.diminfo[0].shape)) __pyx_t_6 = 0;
    if (__pyx_t_52 < 0) {
      __pyx_t_52 += __pyx_pybuffernd_bamfile_data.diminfo[1].shape;
      if (unlikely(__pyx_t_52 < 0)) __pyx_t_6 = 1;
    } else if (unlikely(__pyx_t_52 >= __pyx_pybuffernd_bamfile_data.diminfo[1].shape)) __pyx_t_6 = 1;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 643, __pyx_L1_error)
    }
    *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer.buf, __pyx_t_51, __pyx_pybuffernd_bamfile_data.diminfo[0].strides, __pyx_t_52, __pyx_pybuffernd_bamfile_data.diminfo[1].strides) = __pyx_t_44;

    /* "_emirge_amplicon.pyx":645
 *         bamfile_data[alignedread_i, 5] = alignedread.is_reverse
 * 
 *         alignedread_i += 1             # <<<<<<<<<<<<<<
 *     assert alignedread_i == bamfile_data.shape[0]
 *     em.bamfile_data = bamfile_data.copy()
 */
    __pyx_v_alignedread_i = (__pyx_v_alignedread_i + 1);

    /* "_emirge_amplicon.pyx":617
 * 
 *     alignedread_i = 0
 *     for alignedread in bamfile:             # <<<<<<<<<<<<<<
 *         #TODO: decide if it's better to assign first to typed variable, or assign directly to bamfile_data
 *         # tid = alignedread.tid
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":646
 * 
 *         alignedread_i += 1
 *     assert alignedread_i == bamfile_data.shape[0]             # <<<<<<<<<<<<<<
 *     em.bamfile_data = bamfile_data.copy()
 *     bamfile.close()
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_alignedread_i == (__pyx_v_bamfile_data->dimensions[0])) != 0))) {
      PyErr_SetNone(PyExc_AssertionError);
      __PYX_ERR(0, 646, __pyx_L1_error)
    }
  }
  #endif

  /* "_emirge_amplicon.pyx":647
 *         alignedread_i += 1
 *     assert alignedread_i == bamfile_data.shape[0]
 *     em.bamfile_data = bamfile_data.copy()             # <<<<<<<<<<<<<<
 *     bamfile.close()
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_bamfile_data), __pyx_n_s_copy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 647, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 647, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_em, __pyx_n_s_bamfile_data, __pyx_t_4) < 0) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":648
 *     assert alignedread_i == bamfile_data.shape[0]
 *     em.bamfile_data = bamfile_data.copy()
 *     bamfile.close()             # <<<<<<<<<<<<<<
 * 
 *     # get base_coverages back in list:
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_close); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 648, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 648, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":651
 * 
 *     # get base_coverages back in list:
 *     for seq_i, base_coverage in enumerate(base_coverages):             # <<<<<<<<<<<<<<
 *         for i in range(base_coverage.shape[0]):
 *             base_coverage[i] = base_coverages_2d[seq_i, i]
 */
  __pyx_t_17 = 0;
  __pyx_t_4 = __pyx_v_base_coverages; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
  for (;;) {
    if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 651, __pyx_L1_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 651, __pyx_L1_error)
    __pyx_t_26 = ((PyArrayObject *)__pyx_t_7);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer, (PyObject*)__pyx_v_base_coverage, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_base_coverage.diminfo[0].strides = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_base_coverage.diminfo[0].shape = __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 651, __pyx_L1_error)
    }
    __pyx_t_26 = 0;
    __Pyx_XDECREF_SET(__pyx_v_base_coverage, ((PyArrayObject *)__pyx_t_7));
    __pyx_t_7 = 0;
    __pyx_v_seq_i = __pyx_t_17;
    __pyx_t_17 = (__pyx_t_17 + 1);

    /* "_emirge_amplicon.pyx":652
 *     # get base_coverages back in list:
 *     for seq_i, base_coverage in enumerate(base_coverages):
 *         for i in range(base_coverage.shape[0]):             # <<<<<<<<<<<<<<
 *             base_coverage[i] = base_coverages_2d[seq_i, i]
 * 
 */
    __pyx_t_28 = (__pyx_v_base_coverage->dimensions[0]);
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_28; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "_emirge_amplicon.pyx":653
 *     for seq_i, base_coverage in enumerate(base_coverages):
 *         for i in range(base_coverage.shape[0]):
 *             base_coverage[i] = base_coverages_2d[seq_i, i]             # <<<<<<<<<<<<<<
 * 
 *     cdef int n_reads_total = reads_mapped.shape[0]
 */
      __pyx_t_53 = __pyx_v_seq_i;
      __pyx_t_54 = __pyx_v_i;
      __pyx_t_30 = -1;
      if (unlikely(__pyx_t_53 >= (size_t)__pyx_pybuffernd_base_coverages_2d.diminfo[0].shape)) __pyx_t_30 = 0;
      if (__pyx_t_54 < 0) {
        __pyx_t_54 += __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape;
        if (unlikely(__pyx_t_54 < 0)) __pyx_t_30 = 1;
      } else if (unlikely(__pyx_t_54 >= __pyx_pybuffernd_base_coverages_2d.diminfo[1].shape)) __pyx_t_30 = 1;
      if (unlikely(__pyx_t_30 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_30);
        __PYX_ERR(0, 653, __pyx_L1_error)
      }
      __pyx_t_55 = __pyx_v_i;
      __pyx_t_30 = -1;
      if (__pyx_t_55 < 0) {
        __pyx_t_55 += __pyx_pybuffernd_base_coverage.diminfo[0].shape;
        if (unlikely(__pyx_t_55 < 0)) __pyx_t_30 = 0;
      } else if (unlikely(__pyx_t_55 >= __pyx_pybuffernd_base_coverage.diminfo[0].shape)) __pyx_t_30 = 0;
      if (unlikely(__pyx_t_30 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_30);
        __PYX_ERR(0, 653, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_base_coverage.rcbuffer->pybuffer.buf, __pyx_t_55, __pyx_pybuffernd_base_coverage.diminfo[0].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer.buf, __pyx_t_53, __pyx_pybuffernd_base_coverages_2d.diminfo[0].strides, __pyx_t_54, __pyx_pybuffernd_base_coverages_2d.diminfo[1].strides));
    }

    /* "_emirge_amplicon.pyx":651
 * 
 *     # get base_coverages back in list:
 *     for seq_i, base_coverage in enumerate(base_coverages):             # <<<<<<<<<<<<<<
 *         for i in range(base_coverage.shape[0]):
 *             base_coverage[i] = base_coverages_2d[seq_i, i]
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":655
 *             base_coverage[i] = base_coverages_2d[seq_i, i]
 * 
 *     cdef int n_reads_total = reads_mapped.shape[0]             # <<<<<<<<<<<<<<
 *     for i in range(n_reads_total):
 *         n_reads_mapped = n_reads_mapped + reads_mapped[i]
 */
  __pyx_v_n_reads_total = (__pyx_v_reads_mapped->dimensions[0]);

  /* "_emirge_amplicon.pyx":656
 * 
 *     cdef int n_reads_total = reads_mapped.shape[0]
 *     for i in range(n_reads_total):             # <<<<<<<<<<<<<<
 *         n_reads_mapped = n_reads_mapped + reads_mapped[i]
 *     em.n_reads_mapped = n_reads_mapped
 */
  __pyx_t_6 = __pyx_v_n_reads_total;
  for (__pyx_t_30 = 0; __pyx_t_30 < __pyx_t_6; __pyx_t_30+=1) {
    __pyx_v_i = __pyx_t_30;

    /* "_emirge_amplicon.pyx":657
 *     cdef int n_reads_total = reads_mapped.shape[0]
 *     for i in range(n_reads_total):
 *         n_reads_mapped = n_reads_mapped + reads_mapped[i]             # <<<<<<<<<<<<<<
 *     em.n_reads_mapped = n_reads_mapped
 *     return
 */
    __pyx_t_56 = __pyx_v_i;
    __pyx_t_57 = -1;
    if (__pyx_t_56 < 0) {
      __pyx_t_56 += __pyx_pybuffernd_reads_mapped.diminfo[0].shape;
      if (unlikely(__pyx_t_56 < 0)) __pyx_t_57 = 0;
    } else if (unlikely(__pyx_t_56 >= __pyx_pybuffernd_reads_mapped.diminfo[0].shape)) __pyx_t_57 = 0;
    if (unlikely(__pyx_t_57 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_57);
      __PYX_ERR(0, 657, __pyx_L1_error)
    }
    __pyx_v_n_reads_mapped = (__pyx_v_n_reads_mapped + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer.buf, __pyx_t_56, __pyx_pybuffernd_reads_mapped.diminfo[0].strides)));
  }

  /* "_emirge_amplicon.pyx":658
 *     for i in range(n_reads_total):
 *         n_reads_mapped = n_reads_mapped + reads_mapped[i]
 *     em.n_reads_mapped = n_reads_mapped             # <<<<<<<<<<<<<<
 *     return
 * 
 */
  __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_reads_mapped); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_em, __pyx_n_s_n_reads_mapped, __pyx_t_4) < 0) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "_emirge_amplicon.pyx":659
 *         n_reads_mapped = n_reads_mapped + reads_mapped[i]
 *     em.n_reads_mapped = n_reads_mapped
 *     return             # <<<<<<<<<<<<<<
 * 
 * def reset_probN(em):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":531
 *     return
 * 
 * def process_bamfile(em, int ascii_offset):             # <<<<<<<<<<<<<<
 *     """
 *     read in bamfile and populate:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_coverage.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("_emirge_amplicon.process_bamfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bamfile_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverage.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_base_coverages_2d.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_coverage.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_reads_mapped.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tid2seq_i.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tid_mapped.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_mode);
  __Pyx_XDECREF(__pyx_v_bamfile);
  __Pyx_XDECREF(__pyx_v_sequence_name2sequence_i);
  __Pyx_XDECREF(__pyx_v_sequence_i2sequence_name);
  __Pyx_XDECREF((PyObject *)__pyx_v_bamfile_data);
  __Pyx_XDECREF((PyObject *)__pyx_v_reads_mapped);
  __Pyx_XDECREF((PyObject *)__pyx_v_base_coverage);
  __Pyx_XDECREF(__pyx_v_samfile_references);
  __Pyx_XDECREF(__pyx_v_samfile_lengths);
  __Pyx_XDECREF((PyObject *)__pyx_v_tid2seq_i);
  __Pyx_XDECREF((PyObject *)__pyx_v_tid_mapped);
  __Pyx_XDECREF(__pyx_v_t_check);
  __Pyx_XDECREF(__pyx_v_alignedread);
  __Pyx_XDECREF(__pyx_v_refname);
  __Pyx_XDECREF((PyObject *)__pyx_v_coverage);
  __Pyx_XDECREF(__pyx_v_base_coverages);
  __Pyx_XDECREF(__pyx_v_max_length);
  __Pyx_XDECREF((PyObject *)__pyx_v_base_coverages_2d);
  __Pyx_XDECREF(__pyx_v_qname_temp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":661
 *     return
 * 
 * def reset_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     sets probN back to zeros for all sequences
 */

/* Python wrapper */
static PyObject *__pyx_pw_16_emirge_amplicon_13reset_probN(PyObject *__pyx_self, PyObject *__pyx_v_em); /*proto*/
static char __pyx_doc_16_emirge_amplicon_12reset_probN[] = "\n    sets probN back to zeros for all sequences\n    gets coverage set for all sequences by dividing current values by sequence lengths\n    does culling based on base_coverages\n    \n    ";
static PyMethodDef __pyx_mdef_16_emirge_amplicon_13reset_probN = {"reset_probN", (PyCFunction)__pyx_pw_16_emirge_amplicon_13reset_probN, METH_O, __pyx_doc_16_emirge_amplicon_12reset_probN};
static PyObject *__pyx_pw_16_emirge_amplicon_13reset_probN(PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("reset_probN (wrapper)", 0);
  __pyx_r = __pyx_pf_16_emirge_amplicon_12reset_probN(__pyx_self, ((PyObject *)__pyx_v_em));

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

static PyObject *__pyx_pf_16_emirge_amplicon_12reset_probN(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_em) {
  PyObject *__pyx_v_mode = NULL;
  PyObject *__pyx_v_bamfile = NULL;
  int __pyx_v_i;
  int __pyx_v_l;
  unsigned int __pyx_v_cov_thresh;
  double __pyx_v_length_thresh;
  double __pyx_v_percent_length_covered;
  int __pyx_v_cullcount;
  PyObject *__pyx_v_references_array = NULL;
  PyObject *__pyx_v_references_lengths = NULL;
  PyObject *__pyx_v_seq_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  unsigned int __pyx_t_8;
  double __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  __Pyx_RefNannySetupContext("reset_probN", 0);

  /* "_emirge_amplicon.pyx":668
 * 
 *     """
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "_emirge_amplicon.pyx":669
 *     """
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"             # <<<<<<<<<<<<<<
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"
 */
    __Pyx_INCREF(__pyx_n_s_rb);
    __pyx_v_mode = __pyx_n_s_rb;

    /* "_emirge_amplicon.pyx":668
 * 
 *     """
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
    goto __pyx_L3;
  }

  /* "_emirge_amplicon.pyx":670
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "_emirge_amplicon.pyx":671
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"             # <<<<<<<<<<<<<<
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 * 
 */
    __Pyx_INCREF(__pyx_n_s_r);
    __pyx_v_mode = __pyx_n_s_r;

    /* "_emirge_amplicon.pyx":670
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  }
  __pyx_L3:;

  /* "_emirge_amplicon.pyx":672
 *     elif em.current_bam_filename.endswith("sam"):
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)             # <<<<<<<<<<<<<<
 * 
 *     cdef int i
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pysam); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Samfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_current_bam_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(!__pyx_v_mode)) { __Pyx_RaiseUnboundLocalError("mode"); __PYX_ERR(0, 672, __pyx_L1_error) }
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_v_mode};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_2);
    __Pyx_INCREF(__pyx_v_mode);
    __Pyx_GIVEREF(__pyx_v_mode);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_mode);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_bamfile = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":676
 *     cdef int i
 *     cdef int l
 *     cdef unsigned int cov_thresh    = em.min_length_coverage_def  # above what coverage             # <<<<<<<<<<<<<<
 *     cdef double length_thresh       = em.min_length_coverage      # percent length required
 *     cdef double percent_length_covered
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_min_length_coverage_def); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyInt_As_unsigned_int(__pyx_t_1); if (unlikely((__pyx_t_8 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 676, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_cov_thresh = __pyx_t_8;

  /* "_emirge_amplicon.pyx":677
 *     cdef int l
 *     cdef unsigned int cov_thresh    = em.min_length_coverage_def  # above what coverage
 *     cdef double length_thresh       = em.min_length_coverage      # percent length required             # <<<<<<<<<<<<<<
 *     cdef double percent_length_covered
 *     cdef int cullcount = 0
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_min_length_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 677, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_length_thresh = __pyx_t_9;

  /* "_emirge_amplicon.pyx":679
 *     cdef double length_thresh       = em.min_length_coverage      # percent length required
 *     cdef double percent_length_covered
 *     cdef int cullcount = 0             # <<<<<<<<<<<<<<
 * 
 *     references_array = np.array(bamfile.references) # slicing these tuples is stupid-slow, for some reason.
 */
  __pyx_v_cullcount = 0;

  /* "_emirge_amplicon.pyx":681
 *     cdef int cullcount = 0
 * 
 *     references_array = np.array(bamfile.references) # slicing these tuples is stupid-slow, for some reason.             # <<<<<<<<<<<<<<
 *     references_lengths = np.array(bamfile.lengths)
 *     for i in range(len(bamfile.lengths)):
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 681, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 681, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_references); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 681, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 681, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_references_array = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":682
 * 
 *     references_array = np.array(bamfile.references) # slicing these tuples is stupid-slow, for some reason.
 *     references_lengths = np.array(bamfile.lengths)             # <<<<<<<<<<<<<<
 *     for i in range(len(bamfile.lengths)):
 *         seq_i = em.sequence_name2sequence_i.get(references_array[i])
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_lengths); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_7};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_7};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_references_lengths = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":683
 *     references_array = np.array(bamfile.references) # slicing these tuples is stupid-slow, for some reason.
 *     references_lengths = np.array(bamfile.lengths)
 *     for i in range(len(bamfile.lengths)):             # <<<<<<<<<<<<<<
 *         seq_i = em.sequence_name2sequence_i.get(references_array[i])
 *         if seq_i is not None:  # since not all seqs in header will be ones with mapped reads
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_lengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 683, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_10; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "_emirge_amplicon.pyx":684
 *     references_lengths = np.array(bamfile.lengths)
 *     for i in range(len(bamfile.lengths)):
 *         seq_i = em.sequence_name2sequence_i.get(references_array[i])             # <<<<<<<<<<<<<<
 *         if seq_i is not None:  # since not all seqs in header will be ones with mapped reads
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_sequence_name2sequence_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 684, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 684, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_references_array, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 684, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_7) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 684, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_seq_i, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "_emirge_amplicon.pyx":685
 *     for i in range(len(bamfile.lengths)):
 *         seq_i = em.sequence_name2sequence_i.get(references_array[i])
 *         if seq_i is not None:  # since not all seqs in header will be ones with mapped reads             # <<<<<<<<<<<<<<
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]
 */
    __pyx_t_3 = (__pyx_v_seq_i != Py_None);
    __pyx_t_11 = (__pyx_t_3 != 0);
    if (__pyx_t_11) {

      /* "_emirge_amplicon.pyx":687
 *         if seq_i is not None:  # since not all seqs in header will be ones with mapped reads
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]             # <<<<<<<<<<<<<<
 *             if percent_length_covered < length_thresh:
 *                 em.probN[seq_i] = None
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_base_coverages); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PyObject_GetItem(__pyx_t_2, __pyx_v_seq_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_From_unsigned_int(__pyx_v_cov_thresh); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_base_coverages); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_GetItem(__pyx_t_1, __pyx_v_seq_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 687, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_percent_length_covered = __pyx_t_9;

      /* "_emirge_amplicon.pyx":688
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]
 *             if percent_length_covered < length_thresh:             # <<<<<<<<<<<<<<
 *                 em.probN[seq_i] = None
 *                 em.coverage[seq_i] = 0
 */
      __pyx_t_11 = ((__pyx_v_percent_length_covered < __pyx_v_length_thresh) != 0);
      if (__pyx_t_11) {

        /* "_emirge_amplicon.pyx":689
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]
 *             if percent_length_covered < length_thresh:
 *                 em.probN[seq_i] = None             # <<<<<<<<<<<<<<
 *                 em.coverage[seq_i] = 0
 *                 cullcount += 1
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 689, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_seq_i, Py_None) < 0)) __PYX_ERR(0, 689, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "_emirge_amplicon.pyx":690
 *             if percent_length_covered < length_thresh:
 *                 em.probN[seq_i] = None
 *                 em.coverage[seq_i] = 0             # <<<<<<<<<<<<<<
 *                 cullcount += 1
 *                 continue
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 690, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_seq_i, __pyx_int_0) < 0)) __PYX_ERR(0, 690, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "_emirge_amplicon.pyx":691
 *                 em.probN[seq_i] = None
 *                 em.coverage[seq_i] = 0
 *                 cullcount += 1             # <<<<<<<<<<<<<<
 *                 continue
 *             # else is a valid seq, so create empty probN matrix
 */
        __pyx_v_cullcount = (__pyx_v_cullcount + 1);

        /* "_emirge_amplicon.pyx":692
 *                 em.coverage[seq_i] = 0
 *                 cullcount += 1
 *                 continue             # <<<<<<<<<<<<<<
 *             # else is a valid seq, so create empty probN matrix
 *             l = references_lengths[i]
 */
        goto __pyx_L4_continue;

        /* "_emirge_amplicon.pyx":688
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]
 *             if percent_length_covered < length_thresh:             # <<<<<<<<<<<<<<
 *                 em.probN[seq_i] = None
 *                 em.coverage[seq_i] = 0
 */
      }

      /* "_emirge_amplicon.pyx":694
 *                 continue
 *             # else is a valid seq, so create empty probN matrix
 *             l = references_lengths[i]             # <<<<<<<<<<<<<<
 *             em.probN[seq_i] = np.zeros((l, 5), dtype=np.float)   #ATCG[other] --> 01234
 *             em.coverage[seq_i] = em.coverage[seq_i] / float(l)
 */
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_references_lengths, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 694, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_l = __pyx_t_12;

      /* "_emirge_amplicon.pyx":695
 *             # else is a valid seq, so create empty probN matrix
 *             l = references_lengths[i]
 *             em.probN[seq_i] = np.zeros((l, 5), dtype=np.float)   #ATCG[other] --> 01234             # <<<<<<<<<<<<<<
 *             em.coverage[seq_i] = em.coverage[seq_i] / float(l)
 *     bamfile.close()
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __Pyx_INCREF(__pyx_int_5);
      __Pyx_GIVEREF(__pyx_int_5);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_5);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_probN); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_v_seq_i, __pyx_t_7) < 0)) __PYX_ERR(0, 695, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "_emirge_amplicon.pyx":696
 *             l = references_lengths[i]
 *             em.probN[seq_i] = np.zeros((l, 5), dtype=np.float)   #ATCG[other] --> 01234
 *             em.coverage[seq_i] = em.coverage[seq_i] / float(l)             # <<<<<<<<<<<<<<
 *     bamfile.close()
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_coverage); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_2 = PyObject_GetItem(__pyx_t_7, __pyx_v_seq_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyFloat_FromDouble(((double)__pyx_v_l)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_coverage); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_v_seq_i, __pyx_t_1) < 0)) __PYX_ERR(0, 696, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "_emirge_amplicon.pyx":685
 *     for i in range(len(bamfile.lengths)):
 *         seq_i = em.sequence_name2sequence_i.get(references_array[i])
 *         if seq_i is not None:  # since not all seqs in header will be ones with mapped reads             # <<<<<<<<<<<<<<
 *             # CULLING: check for coverage > 0 across a % threshold of bases
 *             percent_length_covered = float((em.base_coverages[seq_i] >= cov_thresh).sum()) / em.base_coverages[seq_i].shape[0]
 */
    }
    __pyx_L4_continue:;
  }

  /* "_emirge_amplicon.pyx":697
 *             em.probN[seq_i] = np.zeros((l, 5), dtype=np.float)   #ATCG[other] --> 01234
 *             em.coverage[seq_i] = em.coverage[seq_i] / float(l)
 *     bamfile.close()             # <<<<<<<<<<<<<<
 * 
 *     # EXPERIMENTAL: if initial iteration, then redistribute Priors out over only sequences that weren't culled.
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_bamfile, __pyx_n_s_close); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":703
 * 
 * 
 *     if em._VERBOSE:             # <<<<<<<<<<<<<<
 *         if cullcount > 0:
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_VERBOSE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 703, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 703, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_11) {

    /* "_emirge_amplicon.pyx":704
 * 
 *     if em._VERBOSE:
 *         if cullcount > 0:             # <<<<<<<<<<<<<<
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)
 * 
 */
    __pyx_t_11 = ((__pyx_v_cullcount > 0) != 0);
    if (__pyx_t_11) {

      /* "_emirge_amplicon.pyx":705
 *     if em._VERBOSE:
 *         if cullcount > 0:
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)             # <<<<<<<<<<<<<<
 * 
 *     return
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_stderr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_cullcount); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_em, __pyx_n_s_iteration_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyInt_From_unsigned_int(__pyx_v_cov_thresh); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_5);
      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Culled_s_sequences_in_iteration, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__Pyx_PrintOne(__pyx_t_7, __pyx_t_5) < 0) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "_emirge_amplicon.pyx":704
 * 
 *     if em._VERBOSE:
 *         if cullcount > 0:             # <<<<<<<<<<<<<<
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)
 * 
 */
    }

    /* "_emirge_amplicon.pyx":703
 * 
 * 
 *     if em._VERBOSE:             # <<<<<<<<<<<<<<
 *         if cullcount > 0:
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)
 */
  }

  /* "_emirge_amplicon.pyx":707
 *             print >> sys.stderr, "Culled %s sequences in iteration %02d due to low fraction of reference sequence bases covered by >= %s reads"%(cullcount, em.iteration_i, cov_thresh)
 * 
 *     return             # <<<<<<<<<<<<<<
 * 
 * @cython.boundscheck(False) # turn off bounds-checking for entire function
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":661
 *     return
 * 
 * def reset_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     sets probN back to zeros for all sequences
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("_emirge_amplicon.reset_probN", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mode);
  __Pyx_XDECREF(__pyx_v_bamfile);
  __Pyx_XDECREF(__pyx_v_references_array);
  __Pyx_XDECREF(__pyx_v_references_lengths);
  __Pyx_XDECREF(__pyx_v_seq_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "_emirge_amplicon.pyx":710
 * 
 * @cython.boundscheck(False) # turn off bounds-checking for entire function
 * cdef np.ndarray[np.uint8_t, ndim=1] seq_alpha2int(char* seq, int seqlen):             # <<<<<<<<<<<<<<
 *     cdef unsigned int i
 *     np_as_ints = np.empty(seqlen, dtype=np.uint8)
 */

static PyArrayObject *__pyx_f_16_emirge_amplicon_seq_alpha2int(char *__pyx_v_seq, int __pyx_v_seqlen) {
  unsigned int __pyx_v_i;
  PyObject *__pyx_v_np_as_ints = NULL;
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  unsigned int __pyx_t_7;
  __Pyx_RefNannySetupContext("seq_alpha2int", 0);

  /* "_emirge_amplicon.pyx":712
 * cdef np.ndarray[np.uint8_t, ndim=1] seq_alpha2int(char* seq, int seqlen):
 *     cdef unsigned int i
 *     np_as_ints = np.empty(seqlen, dtype=np.uint8)             # <<<<<<<<<<<<<<
 *     for i in range(seqlen):
 *         np_as_ints[i] = base_alpha2int(seq[i])
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_seqlen); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_uint8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 712, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_np_as_ints = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "_emirge_amplicon.pyx":713
 *     cdef unsigned int i
 *     np_as_ints = np.empty(seqlen, dtype=np.uint8)
 *     for i in range(seqlen):             # <<<<<<<<<<<<<<
 *         np_as_ints[i] = base_alpha2int(seq[i])
 *     return np_as_ints
 */
  __pyx_t_6 = __pyx_v_seqlen;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "_emirge_amplicon.pyx":714
 *     np_as_ints = np.empty(seqlen, dtype=np.uint8)
 *     for i in range(seqlen):
 *         np_as_ints[i] = base_alpha2int(seq[i])             # <<<<<<<<<<<<<<
 *     return np_as_ints
 * 
 */
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_f_16_emirge_amplicon_base_alpha2int((__pyx_v_seq[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_SetItemInt(__pyx_v_np_as_ints, __pyx_v_i, __pyx_t_5, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0) < 0)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }

  /* "_emirge_amplicon.pyx":715
 *     for i in range(seqlen):
 *         np_as_ints[i] = base_alpha2int(seq[i])
 *     return np_as_ints             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  if (!(likely(((__pyx_v_np_as_ints) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_np_as_ints, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 715, __pyx_L1_error)
  __Pyx_INCREF(__pyx_v_np_as_ints);
  __pyx_r = ((PyArrayObject *)__pyx_v_np_as_ints);
  goto __pyx_L0;

  /* "_emirge_amplicon.pyx":710
 * 
 * @cython.boundscheck(False) # turn off bounds-checking for entire function
 * cdef np.ndarray[np.uint8_t, ndim=1] seq_alpha2int(char* seq, int seqlen):             # <<<<<<<<<<<<<<
 *     cdef unsigned int i
 *     np_as_ints = np.empty(seqlen, dtype=np.uint8)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("_emirge_amplicon.seq_alpha2int", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_np_as_ints);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":197
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_copy_shape;
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_v_hasfields;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  char *__pyx_t_7;
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":203
 *             # of flags
 * 
 *             if info == NULL: return             # <<<<<<<<<<<<<<
 * 
 *             cdef int copy_shape, i, ndim
 */
  __pyx_t_1 = ((__pyx_v_info == NULL) != 0);
  if (__pyx_t_1) {
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":206
 * 
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":207
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":209
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":211
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":212
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 copy_shape = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 copy_shape = 0
 */
    __pyx_v_copy_shape = 1;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":211
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
    goto __pyx_L4;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":214
 *                 copy_shape = 1
 *             else:
 *                 copy_shape = 0             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
  /*else*/ {
    __pyx_v_copy_shape = 0;
  }
  __pyx_L4:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L6_bool_binop_done;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":217
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L6_bool_binop_done:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":218
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 218, __pyx_L1_error)

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L9_bool_binop_done;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":221
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L9_bool_binop_done:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":222
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 222, __pyx_L1_error)

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":224
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if copy_shape:
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":225
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if copy_shape:
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":226
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  __pyx_t_1 = (__pyx_v_copy_shape != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":229
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2)));

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":230
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __pyx_t_4 = __pyx_v_ndim;
    for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
      __pyx_v_i = __pyx_t_5;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":232
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":233
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":226
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
    goto __pyx_L11;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":235
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
  /*else*/ {
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":236
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L11:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":237
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __pyx_v_info->suboffsets = NULL;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":238
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":239
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0));

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":242
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef int offset
 */
  __pyx_v_f = NULL;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":243
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef int offset
 * 
 */
  __pyx_t_3 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":246
 *             cdef int offset
 * 
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields and not copy_shape:
 */
  __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":248
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
  __pyx_t_2 = ((!(__pyx_v_hasfields != 0)) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L15_bool_binop_done;
  }
  __pyx_t_2 = ((!(__pyx_v_copy_shape != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L15_bool_binop_done:;
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":250
 *             if not hasfields and not copy_shape:
 *                 # do not call releasebuffer
 *                 info.obj = None             # <<<<<<<<<<<<<<
 *             else:
 *                 # need to call releasebuffer
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = Py_None;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":248
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
    goto __pyx_L14;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":253
 *             else:
 *                 # need to call releasebuffer
 *                 info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields:
 */
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
  }
  __pyx_L14:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":255
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __pyx_t_1 = ((!(__pyx_v_hasfields != 0)) != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":256
 * 
 *             if not hasfields:
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __pyx_t_4 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_4;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '>') != 0);
    if (!__pyx_t_2) {
      goto __pyx_L20_next_or;
    } else {
    }
    __pyx_t_2 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_L20_next_or:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":258
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '<') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_t_2 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L19_bool_binop_done:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    if (__pyx_t_1) {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":259
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(1, 259, __pyx_L1_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":260
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    switch (__pyx_v_t) {
      case NPY_BYTE:
      __pyx_v_f = ((char *)"b");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":261
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
      case NPY_UBYTE:
      __pyx_v_f = ((char *)"B");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":262
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
      case NPY_SHORT:
      __pyx_v_f = ((char *)"h");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
      case NPY_USHORT:
      __pyx_v_f = ((char *)"H");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":264
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
      case NPY_INT:
      __pyx_v_f = ((char *)"i");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":265
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
      case NPY_UINT:
      __pyx_v_f = ((char *)"I");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":266
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
      case NPY_LONG:
      __pyx_v_f = ((char *)"l");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":267
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
      case NPY_ULONG:
      __pyx_v_f = ((char *)"L");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":268
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
      case NPY_LONGLONG:
      __pyx_v_f = ((char *)"q");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":269
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
      case NPY_ULONGLONG:
      __pyx_v_f = ((char *)"Q");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":270
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
      case NPY_FLOAT:
      __pyx_v_f = ((char *)"f");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":271
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
      case NPY_DOUBLE:
      __pyx_v_f = ((char *)"d");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":272
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
      case NPY_LONGDOUBLE:
      __pyx_v_f = ((char *)"g");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":273
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
      case NPY_CFLOAT:
      __pyx_v_f = ((char *)"Zf");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":274
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
      case NPY_CDOUBLE:
      __pyx_v_f = ((char *)"Zd");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":275
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
      case NPY_CLONGDOUBLE:
      __pyx_v_f = ((char *)"Zg");
      break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":276
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      case NPY_OBJECT:
      __pyx_v_f = ((char *)"O");
      break;
      default:

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":278
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 278, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(1, 278, __pyx_L1_error)
      break;
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":279
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":280
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":255
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":282
 *                 return
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
  /*else*/ {
    __pyx_v_info->format = ((char *)malloc(0xFF));

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":283
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":284
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __pyx_v_offset = 0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":285
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,             # <<<<<<<<<<<<<<
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 */
    __pyx_t_7 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 0xFF), (&__pyx_v_offset)); if (unlikely(__pyx_t_7 == NULL)) __PYX_ERR(1, 285, __pyx_L1_error)
    __pyx_v_f = __pyx_t_7;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":288
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = '\x00';
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":197
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":290
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":291
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":292
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)
 */
    free(__pyx_v_info->format);

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":291
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":293
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    free(__pyx_v_info->strides);

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":293
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":290
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

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

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":770
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":771
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":770
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":773
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":774
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 774, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":773
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":776
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":777
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":776
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":779
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":780
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":779
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":782
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":783
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":782
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":785
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  long __pyx_t_8;
  char *__pyx_t_9;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":790
 * 
 *     cdef dtype child
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":791
 *     cdef dtype child
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(__pyx_v_descr->names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(1, 794, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 794, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":795
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    if (unlikely(__pyx_v_descr->fields == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 795, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 795, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":796
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 */
    if (likely(__pyx_v_fields != Py_None)) {
      PyObject* sequence = __pyx_v_fields;
      #if !CYTHON_COMPILING_IN_PYPY
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(1, 796, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 796, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 796, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 796, __pyx_L1_error)
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) __PYX_ERR(1, 796, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3));
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 798, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 798, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 798, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0);
    if (__pyx_t_6) {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 799, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(1, 799, __pyx_L1_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '>') != 0);
    if (!__pyx_t_7) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_7 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":802
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '<') != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_7 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_6 = __pyx_t_7;
    __pyx_L7_bool_binop_done:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    if (__pyx_t_6) {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 803, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(1, 803, __pyx_L1_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":813
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 813, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 813, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 813, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!__pyx_t_6) break;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":814
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 0x78;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":815
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":816
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_8 = 0;
      (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + 1);
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":818
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_8 = 0;
    (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + __pyx_v_child->elsize);

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0);
    if (__pyx_t_6) {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":821
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 821, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0);
      if (__pyx_t_6) {

        /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 823, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(1, 823, __pyx_L1_error)

        /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":826
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_BYTE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 826, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 826, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 826, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":827
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UBYTE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 827, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 827, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 827, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":828
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_SHORT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 828, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 828, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 828, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x68;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":829
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_USHORT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 829, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 829, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 829, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":830
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_INT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 830, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 830, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 830, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x69;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":831
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UINT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 831, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 831, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 831, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":832
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 832, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 832, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x6C;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":833
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 833, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 833, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 833, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":834
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 834, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 834, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 834, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x71;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":835
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 835, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 835, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 835, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":836
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_FLOAT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 836, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 836, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 836, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x66;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":837
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 837, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 837, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x64;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":838
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x67;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":839
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 839, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x66;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":840
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 840, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 840, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 840, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x64;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":841
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 841, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 841, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 841, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x67;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":842
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_OBJECT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 842, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 842, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 842, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L15;
      }

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":844
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
      /*else*/ {
        __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 844, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 844, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 844, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(1, 844, __pyx_L1_error)
      }
      __pyx_L15:;

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":845
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
      goto __pyx_L13;
    }

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":849
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
    /*else*/ {
      __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_9 == NULL)) __PYX_ERR(1, 849, __pyx_L1_error)
      __pyx_v_f = __pyx_t_9;
    }
    __pyx_L13:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":850
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":785
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":968
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":969
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":968
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
    goto __pyx_L3;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":971
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
  /*else*/ {
    Py_INCREF(__pyx_v_base);

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":972
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":973
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":974
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

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

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":976
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":978
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":980
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":976
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

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

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":985
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_array()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_array", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":986
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":987
 * cdef inline int import_array() except -1:
 *     try:
 *         _import_array()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")
 */
      __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 987, __pyx_L3_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":986
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":988
 *     try:
 *         _import_array()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 988, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":989
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 989, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(1, 989, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":986
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L10_try_end:;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":985
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_array()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":991
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_umath", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":992
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":993
 * cdef inline int import_umath() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 993, __pyx_L3_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":992
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":994
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 994, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":995
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 995, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(1, 995, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":992
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L10_try_end:;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":991
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":997
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_ufunc", 0);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":998
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":999
 * cdef inline int import_ufunc() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 999, __pyx_L3_error)

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":998
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":1000
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(1, 1000, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":1001
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1001, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(1, 1001, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":998
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L10_try_end:;
  }

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":997
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "_emirge_amplicon",
    __pyx_k_emirge_amplicon_pyx_contains_h, /* 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_Culled_s_sequences_in_iteration, __pyx_k_Culled_s_sequences_in_iteration, sizeof(__pyx_k_Culled_s_sequences_in_iteration), 0, 0, 1, 0},
  {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1},
  {&__pyx_n_s_DEFAULT_ERROR, __pyx_k_DEFAULT_ERROR, sizeof(__pyx_k_DEFAULT_ERROR), 0, 0, 1, 1},
  {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0},
  {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0},
  {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_n_s_M, __pyx_k_M, sizeof(__pyx_k_M), 0, 0, 1, 1},
  {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s_Samfile, __pyx_k_Samfile, sizeof(__pyx_k_Samfile), 0, 0, 1, 1},
  {&__pyx_n_s_VERBOSE, __pyx_k_VERBOSE, sizeof(__pyx_k_VERBOSE), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_WARNING_invalid_base_in_base_alp, __pyx_k_WARNING_invalid_base_in_base_alp, sizeof(__pyx_k_WARNING_invalid_base_in_base_alp), 0, 0, 1, 0},
  {&__pyx_n_s_alignedread, __pyx_k_alignedread, sizeof(__pyx_k_alignedread), 0, 0, 1, 1},
  {&__pyx_n_s_alignedread_i, __pyx_k_alignedread_i, sizeof(__pyx_k_alignedread_i), 0, 0, 1, 1},
  {&__pyx_n_s_aln_code, __pyx_k_aln_code, sizeof(__pyx_k_aln_code), 0, 0, 1, 1},
  {&__pyx_n_s_aln_columns, __pyx_k_aln_columns, sizeof(__pyx_k_aln_columns), 0, 0, 1, 1},
  {&__pyx_n_s_alncode_list, __pyx_k_alncode_list, sizeof(__pyx_k_alncode_list), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_ascii_offset, __pyx_k_ascii_offset, sizeof(__pyx_k_ascii_offset), 0, 0, 1, 1},
  {&__pyx_n_s_bam, __pyx_k_bam, sizeof(__pyx_k_bam), 0, 0, 1, 1},
  {&__pyx_n_s_bamfile, __pyx_k_bamfile, sizeof(__pyx_k_bamfile), 0, 0, 1, 1},
  {&__pyx_n_s_bamfile_data, __pyx_k_bamfile_data, sizeof(__pyx_k_bamfile_data), 0, 0, 1, 1},
  {&__pyx_n_s_base_coverage, __pyx_k_base_coverage, sizeof(__pyx_k_base_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_base_coverages, __pyx_k_base_coverages, sizeof(__pyx_k_base_coverages), 0, 0, 1, 1},
  {&__pyx_n_s_base_coverages_2d, __pyx_k_base_coverages_2d, sizeof(__pyx_k_base_coverages_2d), 0, 0, 1, 1},
  {&__pyx_n_s_base_sum, __pyx_k_base_sum, sizeof(__pyx_k_base_sum), 0, 0, 1, 1},
  {&__pyx_n_s_bisect, __pyx_k_bisect, sizeof(__pyx_k_bisect), 0, 0, 1, 1},
  {&__pyx_n_s_bisect_left, __pyx_k_bisect_left, sizeof(__pyx_k_bisect_left), 0, 0, 1, 1},
  {&__pyx_n_s_calc_likelihood, __pyx_k_calc_likelihood, sizeof(__pyx_k_calc_likelihood), 0, 0, 1, 1},
  {&__pyx_n_s_calc_posteriors, __pyx_k_calc_posteriors, sizeof(__pyx_k_calc_posteriors), 0, 0, 1, 1},
  {&__pyx_n_s_calc_probN, __pyx_k_calc_probN, sizeof(__pyx_k_calc_probN), 0, 0, 1, 1},
  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_col, __pyx_k_col, sizeof(__pyx_k_col), 0, 0, 1, 1},
  {&__pyx_n_s_convert_t0, __pyx_k_convert_t0, sizeof(__pyx_k_convert_t0), 0, 0, 1, 1},
  {&__pyx_n_s_coo_matrix, __pyx_k_coo_matrix, sizeof(__pyx_k_coo_matrix), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_count, __pyx_k_count, sizeof(__pyx_k_count), 0, 0, 1, 1},
  {&__pyx_n_s_count_a, __pyx_k_count_a, sizeof(__pyx_k_count_a), 0, 0, 1, 1},
  {&__pyx_n_s_count_cigar_aln, __pyx_k_count_cigar_aln, sizeof(__pyx_k_count_cigar_aln), 0, 0, 1, 1},
  {&__pyx_n_s_cov_thresh, __pyx_k_cov_thresh, sizeof(__pyx_k_cov_thresh), 0, 0, 1, 1},
  {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_ctime, __pyx_k_ctime, sizeof(__pyx_k_ctime), 0, 0, 1, 1},
  {&__pyx_n_s_cullcount, __pyx_k_cullcount, sizeof(__pyx_k_cullcount), 0, 0, 1, 1},
  {&__pyx_n_s_current_bam_filename, __pyx_k_current_bam_filename, sizeof(__pyx_k_current_bam_filename), 0, 0, 1, 1},
  {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
  {&__pyx_n_s_datetime, __pyx_k_datetime, sizeof(__pyx_k_datetime), 0, 0, 1, 1},
  {&__pyx_n_s_dead_seqs, __pyx_k_dead_seqs, sizeof(__pyx_k_dead_seqs), 0, 0, 1, 1},
  {&__pyx_n_s_denominator, __pyx_k_denominator, sizeof(__pyx_k_denominator), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_em, __pyx_k_em, sizeof(__pyx_k_em), 0, 0, 1, 1},
  {&__pyx_n_s_emirge_amplicon, __pyx_k_emirge_amplicon, sizeof(__pyx_k_emirge_amplicon), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_empty_like, __pyx_k_empty_like, sizeof(__pyx_k_empty_like), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 0, 1, 1},
  {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_float, __pyx_k_float, sizeof(__pyx_k_float), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_hi, __pyx_k_hi, sizeof(__pyx_k_hi), 0, 0, 1, 1},
  {&__pyx_n_s_hit_i, __pyx_k_hit_i, sizeof(__pyx_k_hit_i), 0, 0, 1, 1},
  {&__pyx_n_s_hit_seq, __pyx_k_hit_seq, sizeof(__pyx_k_hit_seq), 0, 0, 1, 1},
  {&__pyx_n_s_hit_unmapped_bases, __pyx_k_hit_unmapped_bases, sizeof(__pyx_k_hit_unmapped_bases), 0, 0, 1, 1},
  {&__pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_k_home_travis_build_csmiller_EMIR, sizeof(__pyx_k_home_travis_build_csmiller_EMIR), 0, 0, 1, 0},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_ii, __pyx_k_ii, sizeof(__pyx_k_ii), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1},
  {&__pyx_n_s_indptr, __pyx_k_indptr, sizeof(__pyx_k_indptr), 0, 0, 1, 1},
  {&__pyx_n_s_initial_iteration, __pyx_k_initial_iteration, sizeof(__pyx_k_initial_iteration), 0, 0, 1, 1},
  {&__pyx_n_s_is_read2, __pyx_k_is_read2, sizeof(__pyx_k_is_read2), 0, 0, 1, 1},
  {&__pyx_n_s_is_reverse, __pyx_k_is_reverse, sizeof(__pyx_k_is_reverse), 0, 0, 1, 1},
  {&__pyx_n_s_iteration_i, __pyx_k_iteration_i, sizeof(__pyx_k_iteration_i), 0, 0, 1, 1},
  {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
  {&__pyx_n_s_ks, __pyx_k_ks, sizeof(__pyx_k_ks), 0, 0, 1, 1},
  {&__pyx_n_s_ks_p, __pyx_k_ks_p, sizeof(__pyx_k_ks_p), 0, 0, 1, 1},
  {&__pyx_n_s_l, __pyx_k_l, sizeof(__pyx_k_l), 0, 0, 1, 1},
  {&__pyx_n_s_length_thresh, __pyx_k_length_thresh, sizeof(__pyx_k_length_thresh), 0, 0, 1, 1},
  {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_lik_col, __pyx_k_lik_col, sizeof(__pyx_k_lik_col), 0, 0, 1, 1},
  {&__pyx_n_s_lik_col_readi, __pyx_k_lik_col_readi, sizeof(__pyx_k_lik_col_readi), 0, 0, 1, 1},
  {&__pyx_n_s_lik_coo, __pyx_k_lik_coo, sizeof(__pyx_k_lik_coo), 0, 0, 1, 1},
  {&__pyx_n_s_lik_data, __pyx_k_lik_data, sizeof(__pyx_k_lik_data), 0, 0, 1, 1},
  {&__pyx_n_s_lik_row, __pyx_k_lik_row, sizeof(__pyx_k_lik_row), 0, 0, 1, 1},
  {&__pyx_n_s_lik_row_seqi, __pyx_k_lik_row_seqi, sizeof(__pyx_k_lik_row_seqi), 0, 0, 1, 1},
  {&__pyx_n_s_likelihoods, __pyx_k_likelihoods, sizeof(__pyx_k_likelihoods), 0, 0, 1, 1},
  {&__pyx_n_s_lo, __pyx_k_lo, sizeof(__pyx_k_lo), 0, 0, 1, 1},
  {&__pyx_n_s_loop_t0, __pyx_k_loop_t0, sizeof(__pyx_k_loop_t0), 0, 0, 1, 1},
  {&__pyx_n_s_low, __pyx_k_low, sizeof(__pyx_k_low), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_matches, __pyx_k_matches, sizeof(__pyx_k_matches), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_length, __pyx_k_max_length, sizeof(__pyx_k_max_length), 0, 0, 1, 1},
  {&__pyx_n_s_mid, __pyx_k_mid, sizeof(__pyx_k_mid), 0, 0, 1, 1},
  {&__pyx_n_s_midval, __pyx_k_midval, sizeof(__pyx_k_midval), 0, 0, 1, 1},
  {&__pyx_n_s_min_length_coverage, __pyx_k_min_length_coverage, sizeof(__pyx_k_min_length_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_min_length_coverage_def, __pyx_k_min_length_coverage_def, sizeof(__pyx_k_min_length_coverage_def), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_n_alignments, __pyx_k_n_alignments, sizeof(__pyx_k_n_alignments), 0, 0, 1, 1},
  {&__pyx_n_s_n_reads, __pyx_k_n_reads, sizeof(__pyx_k_n_reads), 0, 0, 1, 1},
  {&__pyx_n_s_n_reads_mapped, __pyx_k_n_reads_mapped, sizeof(__pyx_k_n_reads_mapped), 0, 0, 1, 1},
  {&__pyx_n_s_n_reads_total, __pyx_k_n_reads_total, sizeof(__pyx_k_n_reads_total), 0, 0, 1, 1},
  {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0},
  {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0},
  {&__pyx_n_s_new_seq_i, __pyx_k_new_seq_i, sizeof(__pyx_k_new_seq_i), 0, 0, 1, 1},
  {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_kp_s_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 0, 1, 0},
  {&__pyx_kp_s_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 0, 1, 0},
  {&__pyx_n_s_one_minus_p, __pyx_k_one_minus_p, sizeof(__pyx_k_one_minus_p), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1},
  {&__pyx_n_s_p_div_3, __pyx_k_p_div_3, sizeof(__pyx_k_p_div_3), 0, 0, 1, 1},
  {&__pyx_n_s_pair_collected, __pyx_k_pair_collected, sizeof(__pyx_k_pair_collected), 0, 0, 1, 1},
  {&__pyx_n_s_pair_i, __pyx_k_pair_i, sizeof(__pyx_k_pair_i), 0, 0, 1, 1},
  {&__pyx_n_s_paired_reads, __pyx_k_paired_reads, sizeof(__pyx_k_paired_reads), 0, 0, 1, 1},
  {&__pyx_n_s_percent_length_covered, __pyx_k_percent_length_covered, sizeof(__pyx_k_percent_length_covered), 0, 0, 1, 1},
  {&__pyx_n_s_populate_reads_arrays, __pyx_k_populate_reads_arrays, sizeof(__pyx_k_populate_reads_arrays), 0, 0, 1, 1},
  {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
  {&__pyx_n_s_posteriors, __pyx_k_posteriors, sizeof(__pyx_k_posteriors), 0, 0, 1, 1},
  {&__pyx_n_s_posteriors_data, __pyx_k_posteriors_data, sizeof(__pyx_k_posteriors_data), 0, 0, 1, 1},
  {&__pyx_n_s_posteriors_indices, __pyx_k_posteriors_indices, sizeof(__pyx_k_posteriors_indices), 0, 0, 1, 1},
  {&__pyx_n_s_posteriors_indptr, __pyx_k_posteriors_indptr, sizeof(__pyx_k_posteriors_indptr), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_priors, __pyx_k_priors, sizeof(__pyx_k_priors), 0, 0, 1, 1},
  {&__pyx_n_s_probN, __pyx_k_probN, sizeof(__pyx_k_probN), 0, 0, 1, 1},
  {&__pyx_n_s_probN_single, __pyx_k_probN_single, sizeof(__pyx_k_probN_single), 0, 0, 1, 1},
  {&__pyx_n_s_process_bamfile, __pyx_k_process_bamfile, sizeof(__pyx_k_process_bamfile), 0, 0, 1, 1},
  {&__pyx_n_s_product, __pyx_k_product, sizeof(__pyx_k_product), 0, 0, 1, 1},
  {&__pyx_n_s_py_seq, __pyx_k_py_seq, sizeof(__pyx_k_py_seq), 0, 0, 1, 1},
  {&__pyx_n_s_pysam, __pyx_k_pysam, sizeof(__pyx_k_pysam), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_qname, __pyx_k_qname, sizeof(__pyx_k_qname), 0, 0, 1, 1},
  {&__pyx_n_s_qname_temp, __pyx_k_qname_temp, sizeof(__pyx_k_qname_temp), 0, 0, 1, 1},
  {&__pyx_n_s_quals, __pyx_k_quals, sizeof(__pyx_k_quals), 0, 0, 1, 1},
  {&__pyx_n_s_query_i, __pyx_k_query_i, sizeof(__pyx_k_query_i), 0, 0, 1, 1},
  {&__pyx_n_s_query_seq, __pyx_k_query_seq, sizeof(__pyx_k_query_seq), 0, 0, 1, 1},
  {&__pyx_n_s_query_unmapped_bases, __pyx_k_query_unmapped_bases, sizeof(__pyx_k_query_unmapped_bases), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 0, 1, 1},
  {&__pyx_n_s_read_i, __pyx_k_read_i, sizeof(__pyx_k_read_i), 0, 0, 1, 1},
  {&__pyx_n_s_read_i_to_cache, __pyx_k_read_i_to_cache, sizeof(__pyx_k_read_i_to_cache), 0, 0, 1, 1},
  {&__pyx_n_s_read_index, __pyx_k_read_index, sizeof(__pyx_k_read_index), 0, 0, 1, 1},
  {&__pyx_n_s_readlength, __pyx_k_readlength, sizeof(__pyx_k_readlength), 0, 0, 1, 1},
  {&__pyx_n_s_readlengths, __pyx_k_readlengths, sizeof(__pyx_k_readlengths), 0, 0, 1, 1},
  {&__pyx_n_s_reads, __pyx_k_reads, sizeof(__pyx_k_reads), 0, 0, 1, 1},
  {&__pyx_n_s_reads1_filepath, __pyx_k_reads1_filepath, sizeof(__pyx_k_reads1_filepath), 0, 0, 1, 1},
  {&__pyx_n_s_reads2_filepath, __pyx_k_reads2_filepath, sizeof(__pyx_k_reads2_filepath), 0, 0, 1, 1},
  {&__pyx_n_s_reads_ascii_offset, __pyx_k_reads_ascii_offset, sizeof(__pyx_k_reads_ascii_offset), 0, 0, 1, 1},
  {&__pyx_n_s_reads_filepath, __pyx_k_reads_filepath, sizeof(__pyx_k_reads_filepath), 0, 0, 1, 1},
  {&__pyx_n_s_reads_mapped, __pyx_k_reads_mapped, sizeof(__pyx_k_reads_mapped), 0, 0, 1, 1},
  {&__pyx_n_s_reads_seen, __pyx_k_reads_seen, sizeof(__pyx_k_reads_seen), 0, 0, 1, 1},
  {&__pyx_n_s_reads_seen_this_round, __pyx_k_reads_seen_this_round, sizeof(__pyx_k_reads_seen_this_round), 0, 0, 1, 1},
  {&__pyx_n_s_readtype_index, __pyx_k_readtype_index, sizeof(__pyx_k_readtype_index), 0, 0, 1, 1},
  {&__pyx_n_s_reference_base, __pyx_k_reference_base, sizeof(__pyx_k_reference_base), 0, 0, 1, 1},
  {&__pyx_n_s_references, __pyx_k_references, sizeof(__pyx_k_references), 0, 0, 1, 1},
  {&__pyx_n_s_references_array, __pyx_k_references_array, sizeof(__pyx_k_references_array), 0, 0, 1, 1},
  {&__pyx_n_s_references_lengths, __pyx_k_references_lengths, sizeof(__pyx_k_references_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_refname, __pyx_k_refname, sizeof(__pyx_k_refname), 0, 0, 1, 1},
  {&__pyx_n_s_reset_probN, __pyx_k_reset_probN, sizeof(__pyx_k_reset_probN), 0, 0, 1, 1},
  {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1},
  {&__pyx_n_s_result_i, __pyx_k_result_i, sizeof(__pyx_k_result_i), 0, 0, 1, 1},
  {&__pyx_n_s_rlen, __pyx_k_rlen, sizeof(__pyx_k_rlen), 0, 0, 1, 1},
  {&__pyx_n_s_row, __pyx_k_row, sizeof(__pyx_k_row), 0, 0, 1, 1},
  {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
  {&__pyx_n_s_sam, __pyx_k_sam, sizeof(__pyx_k_sam), 0, 0, 1, 1},
  {&__pyx_n_s_samfile_lengths, __pyx_k_samfile_lengths, sizeof(__pyx_k_samfile_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_samfile_references, __pyx_k_samfile_references, sizeof(__pyx_k_samfile_references), 0, 0, 1, 1},
  {&__pyx_n_s_scipy, __pyx_k_scipy, sizeof(__pyx_k_scipy), 0, 0, 1, 1},
  {&__pyx_n_s_seconds, __pyx_k_seconds, sizeof(__pyx_k_seconds), 0, 0, 1, 1},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_seq_bases, __pyx_k_seq_bases, sizeof(__pyx_k_seq_bases), 0, 0, 1, 1},
  {&__pyx_n_s_seq_i, __pyx_k_seq_i, sizeof(__pyx_k_seq_i), 0, 0, 1, 1},
  {&__pyx_n_s_sequence_i2sequence_name, __pyx_k_sequence_i2sequence_name, sizeof(__pyx_k_sequence_i2sequence_name), 0, 0, 1, 1},
  {&__pyx_n_s_sequence_i2sequence_name_array, __pyx_k_sequence_i2sequence_name_array, sizeof(__pyx_k_sequence_i2sequence_name_array), 0, 0, 1, 1},
  {&__pyx_n_s_sequence_name2sequence_i, __pyx_k_sequence_name2sequence_i, sizeof(__pyx_k_sequence_name2sequence_i), 0, 0, 1, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_sort_indices, __pyx_k_sort_indices, sizeof(__pyx_k_sort_indices), 0, 0, 1, 1},
  {&__pyx_n_s_sparse, __pyx_k_sparse, sizeof(__pyx_k_sparse), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_stderr, __pyx_k_stderr, sizeof(__pyx_k_stderr), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_t0, __pyx_k_t0, sizeof(__pyx_k_t0), 0, 0, 1, 1},
  {&__pyx_n_s_t_check, __pyx_k_t_check, sizeof(__pyx_k_t_check), 0, 0, 1, 1},
  {&__pyx_n_s_td, __pyx_k_td, sizeof(__pyx_k_td), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1},
  {&__pyx_n_s_tid2seq_i, __pyx_k_tid2seq_i, sizeof(__pyx_k_tid2seq_i), 0, 0, 1, 1},
  {&__pyx_n_s_tid_mapped, __pyx_k_tid_mapped, sizeof(__pyx_k_tid_mapped), 0, 0, 1, 1},
  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
  {&__pyx_n_s_timedelta, __pyx_k_timedelta, sizeof(__pyx_k_timedelta), 0, 0, 1, 1},
  {&__pyx_n_s_tocoo, __pyx_k_tocoo, sizeof(__pyx_k_tocoo), 0, 0, 1, 1},
  {&__pyx_n_s_tocsr, __pyx_k_tocsr, sizeof(__pyx_k_tocsr), 0, 0, 1, 1},
  {&__pyx_n_s_uint, __pyx_k_uint, sizeof(__pyx_k_uint), 0, 0, 1, 1},
  {&__pyx_n_s_uint32, __pyx_k_uint32, sizeof(__pyx_k_uint32), 0, 0, 1, 1},
  {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1},
  {&__pyx_kp_s_unknown_alignment_code_s, __pyx_k_unknown_alignment_code_s, sizeof(__pyx_k_unknown_alignment_code_s), 0, 0, 1, 0},
  {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0},
  {&__pyx_n_s_unmapped_bases, __pyx_k_unmapped_bases, sizeof(__pyx_k_unmapped_bases), 0, 0, 1, 1},
  {&__pyx_n_s_weight, __pyx_k_weight, sizeof(__pyx_k_weight), 0, 0, 1, 1},
  {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
  {&__pyx_n_s_zeros_like, __pyx_k_zeros_like, sizeof(__pyx_k_zeros_like), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 62, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 129, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 357, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 485, __pyx_L1_error)
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 609, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(1, 799, __pyx_L1_error)
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 989, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "_emirge_amplicon.pyx":543
 *     # not to pipe it to samtools, even though CPU load (always < 100%
 *     # ) doesn't explain this)
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_bam); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "_emirge_amplicon.pyx":545
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_n_s_sam); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "_emirge_amplicon.pyx":668
 * 
 *     """
 *     if em.current_bam_filename.endswith("bam"):             # <<<<<<<<<<<<<<
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_bam); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "_emirge_amplicon.pyx":670
 *     if em.current_bam_filename.endswith("bam"):
 *         mode = "rb"
 *     elif em.current_bam_filename.endswith("sam"):             # <<<<<<<<<<<<<<
 *         mode = "r"
 *     bamfile = pysam.Samfile(em.current_bam_filename, mode)
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_n_s_sam); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":218
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":222
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 222, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":259
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(1, 259, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(1, 823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":989
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(1, 989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":995
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":1001
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(1, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "_emirge_amplicon.pyx":78
 * 
 * @cython.boundscheck(False)
 * def _calc_likelihood(em):             # <<<<<<<<<<<<<<
 *     """
 *     Cython helper function with typed data structures, fast looping.
 */
  __pyx_tuple__14 = PyTuple_Pack(30, __pyx_n_s_em, __pyx_n_s_t0, __pyx_n_s_bamfile_data, __pyx_n_s_reads, __pyx_n_s_quals, __pyx_n_s_probN, __pyx_n_s_paired_reads, __pyx_n_s_l, __pyx_n_s_lik_row_seqi, __pyx_n_s_lik_col_readi, __pyx_n_s_lik_data, __pyx_n_s_alignedread_i, __pyx_n_s_seq_i, __pyx_n_s_read_i, __pyx_n_s_pair_i, __pyx_n_s_rlen, __pyx_n_s_pos, __pyx_n_s_is_reverse, __pyx_n_s_p, __pyx_n_s_s, __pyx_n_s_result, __pyx_n_s_i, __pyx_n_s_ii, __pyx_n_s_j, __pyx_n_s_pair_collected, __pyx_n_s_result_i, __pyx_n_s_probN_single, __pyx_n_s_dead_seqs, __pyx_n_s_loop_t0, __pyx_n_s_td); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);
  __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 30, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_calc_likelihood, 78, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 78, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":198
 * 
 * @cython.boundscheck(False)
 * def _calc_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     helper function to emirge_amplicon.py calc_probN
 */
  __pyx_tuple__16 = PyTuple_Pack(46, __pyx_n_s_em, __pyx_n_s_initial_iteration, __pyx_n_s_reads, __pyx_n_s_quals, __pyx_n_s_bamfile_data, __pyx_n_s_priors, __pyx_n_s_posteriors_data, __pyx_n_s_posteriors_indices, __pyx_n_s_posteriors_indptr, __pyx_n_s_convert_t0, __pyx_n_s_posteriors, __pyx_n_s_t_check, __pyx_n_s_probN, __pyx_n_s_alignedread_i, __pyx_n_s_seq_i, __pyx_n_s_read_i, __pyx_n_s_pair_i, __pyx_n_s_rlen, __pyx_n_s_pos, __pyx_n_s_is_reverse, __pyx_n_s_i, __pyx_n_s_ii, __pyx_n_s_j, __pyx_n_s_start, __pyx_n_s_end, __pyx_n_s_low, __pyx_n_s_mid, __pyx_n_s_hi, __pyx_n_s_midval, __pyx_n_s_weight, __pyx_n_s_probN_single, __pyx_n_s_reads_seen, __pyx_n_s_reads_seen_this_round, __pyx_n_s_dead_seqs, __pyx_n_s_loop_t0, __pyx_n_s_lo, __pyx_n_s_td, __pyx_n_s_base_sum, __pyx_n_s_seq_bases, __pyx_n_s_unmapped_bases, __pyx_n_s_seq, __pyx_n_s_reference_base, __pyx_n_s_one_minus_p, __pyx_n_s_p_div_3, __pyx_n_s_sequence_i2sequence_name_array, __pyx_n_s_py_seq); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 198, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 46, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_calc_probN, 198, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 198, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":399
 * # will I want to add @cython.boundscheck(False) ?
 * @cython.boundscheck(False)
 * def _calc_posteriors(em):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates Pr(S|R) for all sequence read pairs
 */
  __pyx_tuple__18 = PyTuple_Pack(10, __pyx_n_s_em, __pyx_n_s_lik_coo, __pyx_n_s_lik_data, __pyx_n_s_lik_row, __pyx_n_s_lik_col, __pyx_n_s_posteriors_data, __pyx_n_s_priors, __pyx_n_s_denominator, __pyx_n_s_i, __pyx_n_s_product); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);
  __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(1, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_calc_posteriors, 399, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 399, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":439
 * 
 * 
 * def count_cigar_aln(char* query_seq, char* hit_seq,             # <<<<<<<<<<<<<<
 *                     np.ndarray[np.uint8_t, ndim=1] query_unmapped_bases,
 *                     np.ndarray[np.uint8_t, ndim=1] hit_unmapped_bases,
 */
  __pyx_tuple__20 = PyTuple_Pack(14, __pyx_n_s_query_seq, __pyx_n_s_hit_seq, __pyx_n_s_query_unmapped_bases, __pyx_n_s_hit_unmapped_bases, __pyx_n_s_query_i, __pyx_n_s_hit_i, __pyx_n_s_alncode_list, __pyx_n_s_matches, __pyx_n_s_aln_columns, __pyx_n_s_count, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_count_a, __pyx_n_s_aln_code); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);
  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(7, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_count_cigar_aln, 439, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 439, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":490
 * 
 * 
 * def populate_reads_arrays(em):             # <<<<<<<<<<<<<<
 *     """
 *     2.  populates:
 */
  __pyx_tuple__22 = PyTuple_Pack(12, __pyx_n_s_em, __pyx_n_s_reads, __pyx_n_s_quals, __pyx_n_s_readlengths, __pyx_n_s_read_index, __pyx_n_s_readtype_index, __pyx_n_s_readlength, __pyx_n_s_i, __pyx_n_s_ascii_offset, __pyx_n_s_ks, __pyx_n_s_ks_p, __pyx_n_s_reads_filepath); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);
  __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(1, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_populate_reads_arrays, 490, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 490, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":531
 *     return
 * 
 * def process_bamfile(em, int ascii_offset):             # <<<<<<<<<<<<<<
 *     """
 *     read in bamfile and populate:
 */
  __pyx_tuple__24 = PyTuple_Pack(35, __pyx_n_s_em, __pyx_n_s_ascii_offset, __pyx_n_s_mode, __pyx_n_s_bamfile, __pyx_n_s_sequence_name2sequence_i, __pyx_n_s_sequence_i2sequence_name, __pyx_n_s_bamfile_data, __pyx_n_s_i, __pyx_n_s_alignedread_i, __pyx_n_s_pos, __pyx_n_s_tid, __pyx_n_s_read_i, __pyx_n_s_seq_i, __pyx_n_s_new_seq_i, __pyx_n_s_pair_i, __pyx_n_s_rlen, __pyx_n_s_read_i_to_cache, __pyx_n_s_qname, __pyx_n_s_is_reverse, __pyx_n_s_n_reads_mapped, __pyx_n_s_reads_mapped, __pyx_n_s_base_coverage, __pyx_n_s_samfile_references, __pyx_n_s_samfile_lengths, __pyx_n_s_tid2seq_i, __pyx_n_s_tid_mapped, __pyx_n_s_t_check, __pyx_n_s_alignedread, __pyx_n_s_refname, __pyx_n_s_coverage, __pyx_n_s_base_coverages, __pyx_n_s_max_length, __pyx_n_s_base_coverages_2d, __pyx_n_s_qname_temp, __pyx_n_s_n_reads_total); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);
  __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 35, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_process_bamfile, 531, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 531, __pyx_L1_error)

  /* "_emirge_amplicon.pyx":661
 *     return
 * 
 * def reset_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     sets probN back to zeros for all sequences
 */
  __pyx_tuple__26 = PyTuple_Pack(12, __pyx_n_s_em, __pyx_n_s_mode, __pyx_n_s_bamfile, __pyx_n_s_i, __pyx_n_s_l, __pyx_n_s_cov_thresh, __pyx_n_s_length_thresh, __pyx_n_s_percent_length_covered, __pyx_n_s_cullcount, __pyx_n_s_references_array, __pyx_n_s_references_lengths, __pyx_n_s_seq_i); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);
  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(1, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_travis_build_csmiller_EMIR, __pyx_n_s_reset_probN, 661, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_1_0 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_float_1_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_3_0 = PyFloat_FromDouble(3.0); if (unlikely(!__pyx_float_3_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_emirge_amplicon(void); /*proto*/
PyMODINIT_FUNC init_emirge_amplicon(void)
#else
PyMODINIT_FUNC PyInit__emirge_amplicon(void); /*proto*/
PyMODINIT_FUNC PyInit__emirge_amplicon(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = 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__emirge_amplicon(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("_emirge_amplicon", __pyx_methods, __pyx_k_emirge_amplicon_pyx_contains_h, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main__emirge_amplicon) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "_emirge_amplicon")) {
      if (unlikely(PyDict_SetItemString(modules, "_emirge_amplicon", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(2, 9, __pyx_L1_error)
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) __PYX_ERR(1, 155, __pyx_L1_error)
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) __PYX_ERR(1, 168, __pyx_L1_error)
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) __PYX_ERR(1, 172, __pyx_L1_error)
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) __PYX_ERR(1, 181, __pyx_L1_error)
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) __PYX_ERR(1, 861, __pyx_L1_error)
  __pyx_ptype_6pykseq_Kseq = __Pyx_ImportType("pykseq", "Kseq", sizeof(struct __pyx_obj_6pykseq_Kseq), 1); if (unlikely(!__pyx_ptype_6pykseq_Kseq)) __PYX_ERR(3, 8, __pyx_L1_error)
  __pyx_vtabptr_6pykseq_Kseq = (struct __pyx_vtabstruct_6pykseq_Kseq*)__Pyx_GetVtable(__pyx_ptype_6pykseq_Kseq->tp_dict); if (unlikely(!__pyx_vtabptr_6pykseq_Kseq)) __PYX_ERR(3, 8, __pyx_L1_error)
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "_emirge_amplicon.pyx":28
 * from libc.math cimport M_E, log, pow as c_pow
 * from cpython.tuple cimport PyTuple_GetItem
 * import numpy as np             # <<<<<<<<<<<<<<
 * cimport numpy as np
 * from scipy import sparse
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":30
 * import numpy as np
 * cimport numpy as np
 * from scipy import sparse             # <<<<<<<<<<<<<<
 * from bisect import bisect_left
 * import sys
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_sparse);
  __Pyx_GIVEREF(__pyx_n_s_sparse);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_sparse);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_sparse); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sparse, __pyx_t_1) < 0) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":31
 * cimport numpy as np
 * from scipy import sparse
 * from bisect import bisect_left             # <<<<<<<<<<<<<<
 * import sys
 * import os
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_bisect_left);
  __Pyx_GIVEREF(__pyx_n_s_bisect_left);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_bisect_left);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_bisect, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_bisect_left); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_bisect_left, __pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":32
 * from scipy import sparse
 * from bisect import bisect_left
 * import sys             # <<<<<<<<<<<<<<
 * import os
 * from time import ctime, time
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":33
 * from bisect import bisect_left
 * import sys
 * import os             # <<<<<<<<<<<<<<
 * from time import ctime, time
 * from datetime import timedelta
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":34
 * import sys
 * import os
 * from time import ctime, time             # <<<<<<<<<<<<<<
 * from datetime import timedelta
 * import pysam
 */
  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_ctime);
  __Pyx_GIVEREF(__pyx_n_s_ctime);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_ctime);
  __Pyx_INCREF(__pyx_n_s_time);
  __Pyx_GIVEREF(__pyx_n_s_time);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_time);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_time, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ctime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctime, __pyx_t_1) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "_emirge_amplicon.pyx":35
 * import os
 * from time import ctime, time
 * from datetime import timedelta             # <<<<<<<<<<<<<<
 * import pysam
 * # cimport ctrie
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_timedelta);
  __Pyx_GIVEREF(__pyx_n_s_timedelta);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_timedelta);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_datetime, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_timedelta, __pyx_t_2) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":36
 * from time import ctime, time
 * from datetime import timedelta
 * import pysam             # <<<<<<<<<<<<<<
 * # cimport ctrie
 * cimport pykseq
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_pysam, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pysam, __pyx_t_1) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":78
 * 
 * @cython.boundscheck(False)
 * def _calc_likelihood(em):             # <<<<<<<<<<<<<<
 *     """
 *     Cython helper function with typed data structures, fast looping.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_1_calc_likelihood, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calc_likelihood, __pyx_t_1) < 0) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":198
 * 
 * @cython.boundscheck(False)
 * def _calc_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     helper function to emirge_amplicon.py calc_probN
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_3_calc_probN, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calc_probN, __pyx_t_1) < 0) __PYX_ERR(0, 198, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":399
 * # will I want to add @cython.boundscheck(False) ?
 * @cython.boundscheck(False)
 * def _calc_posteriors(em):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates Pr(S|R) for all sequence read pairs
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_5_calc_posteriors, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calc_posteriors, __pyx_t_1) < 0) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":439
 * 
 * 
 * def count_cigar_aln(char* query_seq, char* hit_seq,             # <<<<<<<<<<<<<<
 *                     np.ndarray[np.uint8_t, ndim=1] query_unmapped_bases,
 *                     np.ndarray[np.uint8_t, ndim=1] hit_unmapped_bases,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_7count_cigar_aln, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_count_cigar_aln, __pyx_t_1) < 0) __PYX_ERR(0, 439, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":490
 * 
 * 
 * def populate_reads_arrays(em):             # <<<<<<<<<<<<<<
 *     """
 *     2.  populates:
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_9populate_reads_arrays, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_populate_reads_arrays, __pyx_t_1) < 0) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":531
 *     return
 * 
 * def process_bamfile(em, int ascii_offset):             # <<<<<<<<<<<<<<
 *     """
 *     read in bamfile and populate:
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_11process_bamfile, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_process_bamfile, __pyx_t_1) < 0) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":661
 *     return
 * 
 * def reset_probN(em):             # <<<<<<<<<<<<<<
 *     """
 *     sets probN back to zeros for all sequences
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_16_emirge_amplicon_13reset_probN, NULL, __pyx_n_s_emirge_amplicon); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reset_probN, __pyx_t_1) < 0) __PYX_ERR(0, 661, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "_emirge_amplicon.pyx":1
 * """             # <<<<<<<<<<<<<<
 * _emirge_amplicon.pyx contains helper cython functions for emirge_amplicon.py
 * 
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../virtualenv/python2.7.9/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":997
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init _emirge_amplicon", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init _emirge_amplicon");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* GetModuleGlobalName */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* PyObjectCall */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyErrFetchRestore */
  #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* WriteUnraisableException */
  static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyCFunctionFastCall */
  #if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    PyObject *result;
    int flags;
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL);
}
#endif  // CYTHON_FAST_PYCCALL

/* PyFunctionFastCall */
  #if CYTHON_FAST_PYCALL
#include "frameobject.h"
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = PyThreadState_GET();
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = f->f_localsplus;
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif  // CPython < 3.6
#endif  // CYTHON_FAST_PYCALL

/* PyObjectCallMethO */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
  #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* PyObjectCallNoArg */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* ExtTypeTest */
      static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* BufferFormatCheck */
      static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
  unsigned int n = 1;
  return *(unsigned char*)(&n) != 0;
}
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t < '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1)
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case 'c': return "'char'";
    case 'b': return "'signed char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c':
        return 'H';
    case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
      } else {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
      }
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count;
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break;
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue;
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static CYTHON_INLINE PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number;
    int ndim = ctx->head->field->type->ndim;
;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    while (*ts && *ts != ')') {
        switch (*ts) {
            case ' ': case '\f': case '\r': case '\n': case '\t': case '\v':  continue;
            default:  break;
        }
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        return ts;
      case ' ':
      case '\r':
      case '\n':
        ++ts;
        break;
      case '<':
        if (!__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T':
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}':
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }
      case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 'p':
        if (ctx->enc_type == *ts && got_Z == ctx->is_complex &&
            ctx->enc_packmode == ctx->new_packmode) {
          ctx->enc_count += ctx->new_count;
          ctx->new_count = 1;
          got_Z = 0;
          ++ts;
          break;
        }
      case 's':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->enc_count = ctx->new_count;
        ctx->enc_packmode = ctx->new_packmode;
        ctx->enc_type = *ts;
        ctx->is_complex = got_Z;
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}
static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  if (obj == Py_None || obj == NULL) {
    __Pyx_ZeroBuffer(buf);
    return 0;
  }
  buf->buf = NULL;
  if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
  if (buf->ndim != nd) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
  }
  if ((unsigned)buf->itemsize != dtype->size) {
    PyErr_Format(PyExc_ValueError,
      "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_ZeroBuffer(buf);
  return -1;
}
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (info->buf == NULL) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}

/* None */
        static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t q = a / b;
    Py_ssize_t r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* BufferFallbackError */
        static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

/* GetItemInt */
        static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* SetItemInt */
        static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return -1;
                    PyErr_Clear();
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) {
#else
    if (is_list || PySequence_Check(o)) {
#endif
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

/* PyIntBinop */
          #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            if (unlikely(b == -1 && ((unsigned long)a) == 0-(unsigned long)a))
                return PyInt_Type.tp_as_number->nb_floor_divide(op1, op2);
            else {
                long q, r;
                q = a / b;
                r = a - q*b;
                q -= ((r != 0) & ((r ^ b) < 0));
                x = q;
            }
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                default: return PyLong_Type.tp_as_number->nb_floor_divide(op1, op2);
            }
        }
                {
                    long q, r;
                    q = a / b;
                    r = a - q*b;
                    q -= ((r != 0) & ((r ^ b) < 0));
                    x = q;
                }
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                {
                    PY_LONG_LONG q, r;
                    q = lla / llb;
                    r = lla - q*llb;
                    q -= ((r != 0) & ((r ^ llb) < 0));
                    llx = q;
                }
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceFloorDivide : PyNumber_FloorDivide)(op1, op2);
}
#endif

/* PyFloatBinop */
          #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_SubtractCObj(PyObject *op1, PyObject *op2, double floatval, CYTHON_UNUSED int inplace) {
    const double a = floatval;
    double b, result;
    if (likely(PyFloat_CheckExact(op2))) {
        b = PyFloat_AS_DOUBLE(op2);
    } else
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        b = (double) PyInt_AS_LONG(op2);
    } else
    #endif
    if (likely(PyLong_CheckExact(op2))) {
        #if CYTHON_USE_PYLONG_INTERNALS
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        switch (size) {
            case  0: b = 0.0; break;
            case -1: b = -(double) digits[0]; break;
            case  1: b = (double) digits[0]; break;
            case -2:
            case 2:
                if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (1 * PyLong_SHIFT < 53))) {
                    b = (double) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -2)
                            b = -b;
                        break;
                    }
                }
            case -3:
            case 3:
                if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53))) {
                    b = (double) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -3)
                            b = -b;
                        break;
                    }
                }
            case -4:
            case 4:
                if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53))) {
                    b = (double) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (4 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -4)
                            b = -b;
                        break;
                    }
                }
            default:
        #else
        {
        #endif
            b = PyLong_AsDouble(op2);
            if (unlikely(b == -1.0 && PyErr_Occurred())) return NULL;
        }
    } else {
        return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
    }
        PyFPE_START_PROTECT("subtract", return NULL)
        result = a - b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* PyFloatBinop */
            #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_DivideObjC(PyObject *op1, PyObject *op2, double floatval, CYTHON_UNUSED int inplace) {
    const double b = floatval;
    double a, result;
    if (likely(PyFloat_CheckExact(op1))) {
        a = PyFloat_AS_DOUBLE(op1);
    } else
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        a = (double) PyInt_AS_LONG(op1);
    } else
    #endif
    if (likely(PyLong_CheckExact(op1))) {
        #if CYTHON_USE_PYLONG_INTERNALS
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        switch (size) {
            case  0: a = 0.0; break;
            case -1: a = -(double) digits[0]; break;
            case  1: a = (double) digits[0]; break;
            case -2:
            case 2:
                if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (1 * PyLong_SHIFT < 53))) {
                    a = (double) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -2)
                            a = -a;
                        break;
                    }
                }
            case -3:
            case 3:
                if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53))) {
                    a = (double) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -3)
                            a = -a;
                        break;
                    }
                }
            case -4:
            case 4:
                if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53))) {
                    a = (double) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (4 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -4)
                            a = -a;
                        break;
                    }
                }
            default:
        #else
        {
        #endif
            a = PyLong_AsDouble(op1);
            if (unlikely(a == -1.0 && PyErr_Occurred())) return NULL;
        }
    } else {
        return (inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2));
    }
        PyFPE_START_PROTECT("divide", return NULL)
        result = a / b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* RaiseArgTupleInvalid */
              static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
              static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
              static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* ArgTypeTest */
              static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

/* RaiseTooManyValuesToUnpack */
              static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
              static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
              static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
              static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* BytesEquals */
              static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
              static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* BufferIndexError */
              static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

/* RaiseException */
              #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* RaiseNoneIterError */
                static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* None */
                static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* PyObjectCallMethod1 */
                static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto done;
#if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyCFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            args = PyTuple_New(2);
            if (unlikely(!args)) goto done;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
done:
    Py_XDECREF(method);
    return result;
}

/* append */
                static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

/* SaveResetException */
                #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* PyErrExceptionMatches */
                #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    return PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* GetException */
                #if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* GetVTable */
                  static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

/* Import */
                  static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
                  static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CodeObjectCache */
                  static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
                  #include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags);
    PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) { __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view); return; }
    Py_DECREF(obj);
    view->obj = NULL;
}
#endif


                  /* CIntFromPyVerify */
                  #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
    const char neg_one = (char) -1, const_zero = (char) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(char) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
    }
}

/* Print */
                  #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0) {
                switch (s[len-1]) {
                    case ' ': break;
                    case '\f': case '\r': case '\n': case '\t': case '\v':
                        PyFile_SoftSpace(f, 0);
                        break;
                    default:  break;
                }
            }
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = PyObject_GetAttr(__pyx_b, __pyx_n_s_print);
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItem(kwargs, __pyx_n_s_file, stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItem(kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItem(__pyx_print_kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) {
    const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(unsigned int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(unsigned int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(unsigned int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(unsigned int),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) {
    const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = (Py_intptr_t) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(Py_intptr_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(Py_intptr_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(Py_intptr_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(Py_intptr_t),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int32(npy_int32 value) {
    const npy_int32 neg_one = (npy_int32) -1, const_zero = (npy_int32) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(npy_int32) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(npy_int32) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int32) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(npy_int32) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int32) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(npy_int32),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* Declarations */
                  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
                  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabsf(b.real) >= fabsf(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                float r = b.imag / b.real;
                float s = 1.0 / (b.real + b.imag * r);
                return __pyx_t_float_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            float r = b.real / b.imag;
            float s = 1.0 / (b.imag + b.real * r);
            return __pyx_t_float_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            float denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_float_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(a, a);
                    case 3:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, a);
                    case 4:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs_float(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

/* Declarations */
                  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
                  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabs(b.real) >= fabs(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                double r = b.imag / b.real;
                double s = 1.0 / (b.real + b.imag * r);
                return __pyx_t_double_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            double r = b.real / b.imag;
            double s = 1.0 / (b.imag + b.real * r);
            return __pyx_t_double_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            double denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_double_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(a, a);
                    case 3:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, a);
                    case 4:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs_double(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

/* CIntToPy */
                  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value) {
    const enum NPY_TYPES neg_one = (enum NPY_TYPES) -1, const_zero = (enum NPY_TYPES) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum NPY_TYPES) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(enum NPY_TYPES) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum NPY_TYPES),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
                  static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) {
    const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(unsigned int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (unsigned int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (unsigned int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(unsigned int, digit, digits[0])
                case 2:
                    if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 2 * PyLong_SHIFT) {
                            return (unsigned int) (((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 3 * PyLong_SHIFT) {
                            return (unsigned int) (((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 4 * PyLong_SHIFT) {
                            return (unsigned int) (((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (unsigned int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(unsigned int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (unsigned int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(unsigned int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(unsigned int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(unsigned int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                            return (unsigned int) ((((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                            return (unsigned int) ((((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) {
                            return (unsigned int) ((((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(unsigned int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            unsigned int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (unsigned int) -1;
        }
    } else {
        unsigned int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (unsigned int) -1;
        val = __Pyx_PyInt_As_unsigned_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to unsigned int");
    return (unsigned int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to unsigned int");
    return (unsigned int) -1;
}

/* CIntFromPy */
                  static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* PrintOne */
                  #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

/* CIntFromPy */
                  static CYTHON_INLINE npy_uint32 __Pyx_PyInt_As_npy_uint32(PyObject *x) {
    const npy_uint32 neg_one = (npy_uint32) -1, const_zero = (npy_uint32) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(npy_uint32) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(npy_uint32, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (npy_uint32) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_uint32) 0;
                case  1: __PYX_VERIFY_RETURN_INT(npy_uint32, digit, digits[0])
                case 2:
                    if (8 * sizeof(npy_uint32) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) >= 2 * PyLong_SHIFT) {
                            return (npy_uint32) (((((npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_uint32) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) >= 3 * PyLong_SHIFT) {
                            return (npy_uint32) (((((((npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_uint32) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) >= 4 * PyLong_SHIFT) {
                            return (npy_uint32) (((((((((npy_uint32)digits[3]) << PyLong_SHIFT) | (npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (npy_uint32) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(npy_uint32) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_uint32, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_uint32) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_uint32, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_uint32) 0;
                case -1: __PYX_VERIFY_RETURN_INT(npy_uint32, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(npy_uint32,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(npy_uint32) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_uint32) (((npy_uint32)-1)*(((((npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(npy_uint32) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_uint32) ((((((npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(npy_uint32) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_uint32) (((npy_uint32)-1)*(((((((npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_uint32) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_uint32) ((((((((npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(npy_uint32) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_uint32) (((npy_uint32)-1)*(((((((((npy_uint32)digits[3]) << PyLong_SHIFT) | (npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_uint32) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_uint32) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_uint32) ((((((((((npy_uint32)digits[3]) << PyLong_SHIFT) | (npy_uint32)digits[2]) << PyLong_SHIFT) | (npy_uint32)digits[1]) << PyLong_SHIFT) | (npy_uint32)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(npy_uint32) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_uint32, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_uint32) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_uint32, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            npy_uint32 val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (npy_uint32) -1;
        }
    } else {
        npy_uint32 val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (npy_uint32) -1;
        val = __Pyx_PyInt_As_npy_uint32(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to npy_uint32");
    return (npy_uint32) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to npy_uint32");
    return (npy_uint32) -1;
}

/* CIntFromPy */
                  static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CheckBinaryVersion */
                  static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* ModuleImport */
                  #ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

/* TypeImport */
                  #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

/* InitStrings */
                  static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = 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
#else
  res = PyNumber_Int(x);
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (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;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
