/* Generated by Cython 0.24.1 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": []
    }, 
    "module_name": "pyquant.cpeaks"
}
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_24_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 PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
  #define CYTHON_USE_PYLONG_INTERNALS 1
#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
#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_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_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_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_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
#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)
#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 PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
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))
#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__pyquant__cpeaks
#define __PYX_HAVE_API__pyquant__cpeaks
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#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_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#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;

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


/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "pyquant/cpeaks.pyx":6
 * cimport numpy as np
 * cimport cython
 * ctypedef np.float_t FLOAT_t             # <<<<<<<<<<<<<<
 * from scipy import optimize, integrate
 * from scipy.interpolate import interp1d
 */
typedef __pyx_t_5numpy_float_t __pyx_t_7pyquant_6cpeaks_FLOAT_t;
/* None.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

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


/*--- Type declarations ---*/
struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit;
struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit2;
struct __pyx_opt_args_7pyquant_6cpeaks_findAllPeaks;
struct __pyx_opt_args_7pyquant_6cpeaks_findEnvelope;

/* "pyquant/cpeaks.pyx":140
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]
 */
struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit {
  int __pyx_n;
  int peak_index;
  PyObject *debug;
};

/* "pyquant/cpeaks.pyx":215
 *     return best
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak, mval
 */
struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit2 {
  int __pyx_n;
  int peak_index;
  PyObject *debug;
};

/* "pyquant/cpeaks.pyx":315
 * 
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,             # <<<<<<<<<<<<<<
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 */
struct __pyx_opt_args_7pyquant_6cpeaks_findAllPeaks {
  int __pyx_n;
  float min_dist;
  PyObject *filter;
  PyObject *bigauss_fit;
  PyObject *rt_peak;
  PyObject *mrm;
  int max_peaks;
  PyObject *debug;
  PyObject *peak_width_start;
  PyObject *snr;
  PyObject *amplitude_filter;
  PyObject *peak_width_end;
};

/* "pyquant/cpeaks.pyx":784
 *     return out
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,             # <<<<<<<<<<<<<<
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):
 */
struct __pyx_opt_args_7pyquant_6cpeaks_findEnvelope {
  int __pyx_n;
  PyObject *measured_mz;
  PyObject *theo_mz;
  PyObject *max_mz;
  PyObject *precursor_ppm;
  PyObject *isotope_ppm;
  PyObject *isotope_ppms;
  PyObject *charge;
  PyObject *debug;
  PyObject *isotope_offset;
  PyObject *isotopologue_limit;
  PyObject *theo_dist;
  PyObject *label;
  PyObject *skip_isotopes;
  PyObject *last_precursor;
  PyObject *quant_method;
  PyObject *reporter_mode;
  PyObject *fragment_scan;
  PyObject *centroid;
  PyObject *contaminant_search;
};

/* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */
struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro {
  PyObject_HEAD
  float __pyx_v_tolerance;
};


/* --- 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_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

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

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

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

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

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

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

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

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

/* PyThreadStateGet.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#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_COMPILING_IN_CPYTHON
#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);

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

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

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

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

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

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

/* None.proto */
static CYTHON_INLINE long __Pyx_mod_long(long, long);

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

#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)
/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

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

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_RemainderObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceRemainder(op1, op2) : PyNumber_Remainder(op1, op2))
#endif

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

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

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

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

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

/* pop_index.proto */
static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix);
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix);
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix);
#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\
    (likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ?\
        __Pyx__PyList_PopIndex(L, py_ix, ix) : (\
        (unlikely(py_ix == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\
            __Pyx__PyObject_PopIndex(L, py_ix)))
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\
    __Pyx_fits_Py_ssize_t(ix, type, is_signed) ?\
        __Pyx__PyList_PopIndex(L, py_ix, ix) : (\
        (unlikely(py_ix == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\
            __Pyx__PyObject_PopIndex(L, py_ix)))
#else
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)\
    __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)
#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) (\
    (unlikely(py_ix == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) :\
        __Pyx__PyObject_PopIndex(L, py_ix))
#endif

/* SaveResetException.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#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_COMPILING_IN_CPYTHON
#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_COMPILING_IN_CPYTHON
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

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

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

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

/* PyFloatBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyFloat_AddObjC(PyObject *op1, PyObject *op2, double floatval, int inplace);
#else
#define __Pyx_PyFloat_AddObjC(op1, op2, floatval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* ListExtend.proto */
static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* PyDictContains.proto */
static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
    int result = PyDict_Contains(dict, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

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

/* py_dict_items.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    ((likely((cfunc)->func)) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
             ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) : __Pyx__CallUnboundCMethod0(cfunc, self)))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* PyObjectSetAttrStr.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#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

/* PyIntBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddCObj(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);

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

/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

/* CythonFunction.proto */
#define __Pyx_CyFunction_USED 1
#include <structmember.h>
#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
#define __Pyx_CYFUNCTION_CCLASS        0x04
#define __Pyx_CyFunction_GetClosure(f)\
    (((__pyx_CyFunctionObject *) (f))->func_closure)
#define __Pyx_CyFunction_GetClassObj(f)\
    (((__pyx_CyFunctionObject *) (f))->func_classobj)
#define __Pyx_CyFunction_Defaults(type, f)\
    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
    PyCFunctionObject func;
#if PY_VERSION_HEX < 0x030500A0
    PyObject *func_weakreflist;
#endif
    PyObject *func_dict;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
    PyObject *func_classobj;
    void *defaults;
    int defaults_pyobjects;
    int flags;
    PyObject *defaults_tuple;
    PyObject *defaults_kwdict;
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations;
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
    __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *self,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
                                                         size_t size,
                                                         int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
                                                            PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __pyx_CyFunction_init(void);

/* PyFloatBinop.proto */
#if CYTHON_COMPILING_IN_CPYTHON
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

/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
#endif

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

/* 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_long(long value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t 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_int(int value);

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

/* None.proto */
static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

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

/* None.proto */
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

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

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

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

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

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

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

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

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

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

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


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

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

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

/* Module declarations from '__builtin__' */

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

/* Module declarations from 'cpython' */

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

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

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

/* Module declarations from 'numpy' */

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

/* Module declarations from 'cython' */

/* Module declarations from 'pyquant.cpeaks' */
static PyTypeObject *__pyx_ptype_7pyquant_6cpeaks___pyx_scope_struct__findMicro = 0;
static int __pyx_f_7pyquant_6cpeaks_within_bounds(PyArrayObject *, PyArrayObject *); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss(PyArrayObject *, float, float, float); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss_ndim(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_gauss_func(PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss_jac(PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss_jac(PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss(PyArrayObject *, float, float, float, float); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss_ndim(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_bigauss_func(PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_fixedMeanFit(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_fixedMeanFit2(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit2 *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_basin_stepper(PyArrayObject *, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_findAllPeaks(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_findAllPeaks *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_findPeak(PyArrayObject *, int); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_get_ppm(float, float, int __pyx_skip_dispatch); /*proto*/
static CYTHON_INLINE int __pyx_f_7pyquant_6cpeaks_within_tolerance(PyObject *, float); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_findEnvelope(PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_findEnvelope *__pyx_optional_args); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t = { "FLOAT_t", NULL, sizeof(__pyx_t_7pyquant_6cpeaks_FLOAT_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_long = { "long", NULL, sizeof(long), { 0 }, 0, IS_UNSIGNED(long) ? 'U' : 'I', IS_UNSIGNED(long), 0 };
#define __Pyx_MODULE_NAME "pyquant.cpeaks"
int __pyx_module_is_main_pyquant__cpeaks = 0;

/* Implementation of 'pyquant.cpeaks' */
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_xrange;
static PyObject *__pyx_builtin_any;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_sorted;
static PyObject *__pyx_builtin_filter;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_RuntimeError;
static const char __pyx_k_i[] = "i";
static const char __pyx_k_v[] = "v";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_y[] = "y";
static const char __pyx_k_lr[] = "lr";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_TNC[] = "TNC";
static const char __pyx_k__18[] = "{}";
static const char __pyx_k__20[] = "{}: {} ---- {}\n";
static const char __pyx_k__23[] = "{} < {}";
static const char __pyx_k_abs[] = "abs";
static const char __pyx_k_any[] = "any";
static const char __pyx_k_bic[] = "bic";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_exp[] = "exp";
static const char __pyx_k_fit[] = "fit";
static const char __pyx_k_fun[] = "fun";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_idx[] = "idx";
static const char __pyx_k_inf[] = "inf";
static const char __pyx_k_int[] = "int";
static const char __pyx_k_jac[] = "jac";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_log[] = "log";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_mrm[] = "mrm";
static const char __pyx_k_out[] = "out";
static const char __pyx_k_pop[] = "pop";
static const char __pyx_k_pos[] = "pos";
static const char __pyx_k_ppm[] = "ppm";
static const char __pyx_k_snr[] = "snr";
static const char __pyx_k_std[] = "std";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_tol[] = "tol";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_axis[] = "axis";
static const char __pyx_k_best[] = "{} - best: {}";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_diff[] = "diff";
static const char __pyx_k_fabs[] = "fabs";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_ftol[] = "ftol";
static const char __pyx_k_int2[] = "int2";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_left[] = "left";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_peak[] = "peak";
static const char __pyx_k_ppms[] = "ppms";
static const char __pyx_k_same[] = "same";
static const char __pyx_k_side[] = "side";
static const char __pyx_k_sign[] = "sign";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_sort[] = "sort";
static const char __pyx_k_sqrt[] = "sqrt";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_SLSQP[] = "SLSQP";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_debug[] = "debug";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_found[] = "found: {}\n";
static const char __pyx_k_guess[] = "guess";
static const char __pyx_k_isnan[] = "isnan";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_label[] = "label";
static const char __pyx_k_new_x[] = "new_x";
static const char __pyx_k_new_y[] = "new_y";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_order[] = "order";
static const char __pyx_k_peaks[] = "peaks";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_right[] = "right";
static const char __pyx_k_scipy[] = "scipy";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_where[] = "where";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_xdata[] = "xdata";
static const char __pyx_k_ydata[] = "ydata";
static const char __pyx_k_zeros[] = "zeros";
static const char __pyx_k_argmax[] = "argmax";
static const char __pyx_k_bounds[] = "bounds";
static const char __pyx_k_charge[] = "charge";
static const char __pyx_k_filter[] = "filter";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_kaiser[] = "kaiser";
static const char __pyx_k_max_mz[] = "max_mz";
static const char __pyx_k_method[] = "method";
static const char __pyx_k_minima[] = "minima";
static const char __pyx_k_offset[] = "offset";
static const char __pyx_k_params[] = "params";
static const char __pyx_k_sorted[] = "sorted";
static const char __pyx_k_stderr[] = "stderr";
static const char __pyx_k_tolist[] = "tolist";
static const char __pyx_k_xrange[] = "xrange";
static const char __pyx_k_NEUTRON[] = "NEUTRON";
static const char __pyx_k_argsort[] = "argsort";
static const char __pyx_k_average[] = "average";
static const char __pyx_k_becomes[] = "becomes";
static const char __pyx_k_indices[] = "indices";
static const char __pyx_k_int_val[] = "int_val";
static const char __pyx_k_isotope[] = "isotope";
static const char __pyx_k_left_is[] = "left is";
static const char __pyx_k_maxiter[] = "maxiter";
static const char __pyx_k_options[] = "options";
static const char __pyx_k_rt_peak[] = "rt_peak";
static const char __pyx_k_spacing[] = "spacing";
static const char __pyx_k_success[] = "success";
static const char __pyx_k_theo_mz[] = "theo_mz";
static const char __pyx_k_weights[] = "weights";
static const char __pyx_k_L_BFGS_B[] = "L-BFGS-B";
static const char __pyx_k_best_fit[] = "best fit";
static const char __pyx_k_centroid[] = "centroid";
static const char __pyx_k_checking[] = "checking {}\n";
static const char __pyx_k_constant[] = "constant";
static const char __pyx_k_convolve[] = "convolve";
static const char __pyx_k_deepcopy[] = "deepcopy";
static const char __pyx_k_envelope[] = "envelope";
static const char __pyx_k_gradient[] = "gradient";
static const char __pyx_k_interp1d[] = "interp1d";
static const char __pyx_k_min_dist[] = "min_dist";
static const char __pyx_k_minimize[] = "minimize";
static const char __pyx_k_observed[] = "observed";
static const char __pyx_k_operator[] = "operator";
static const char __pyx_k_optimize[] = "optimize";
static const char __pyx_k_ret_dict[] = "ret_dict";
static const char __pyx_k_right_is[] = "right is";
static const char __pyx_k_start_mz[] = "start_mz";
static const char __pyx_k_analyzing[] = "analyzing";
static const char __pyx_k_argrelmax[] = "argrelmax";
static const char __pyx_k_argrelmin[] = "argrelmin";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_findMicro[] = "findMicro";
static const char __pyx_k_gauss_jac[] = "gauss_jac";
static const char __pyx_k_integrate[] = "integrate";
static const char __pyx_k_max_peaks[] = "max_peaks";
static const char __pyx_k_peak_mean[] = "peak_mean";
static const char __pyx_k_theo_dist[] = "theo_dist";
static const char __pyx_k_tolerance[] = "tolerance";
static const char __pyx_k_traceback[] = "traceback";
static const char __pyx_k_transpose[] = "transpose";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_attrgetter[] = "attrgetter";
static const char __pyx_k_format_exc[] = "format_exc";
static const char __pyx_k_gauss_func[] = "gauss_func";
static const char __pyx_k_itemgetter[] = "itemgetter";
static const char __pyx_k_peak_index[] = "peak_index";
static const char __pyx_k_OrderedDict[] = "OrderedDict";
static const char __pyx_k_bigauss_fit[] = "bigauss_fit";
static const char __pyx_k_bigauss_jac[] = "bigauss_jac";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_concatenate[] = "concatenate";
static const char __pyx_k_contains_rt[] = "_contains_rt";
static const char __pyx_k_final_peaks[] = "final peaks: {}\n";
static const char __pyx_k_isotope_ppm[] = "isotope_ppm";
static const char __pyx_k_measured_mz[] = "measured_mz";
static const char __pyx_k_theoretical[] = "theoretical";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_bigauss_func[] = "bigauss_func";
static const char __pyx_k_findAllPeaks[] = "findAllPeaks";
static const char __pyx_k_find_nearest[] = "find_nearest";
static const char __pyx_k_intersection[] = "intersection";
static const char __pyx_k_isotope_ppms[] = "isotope_ppms";
static const char __pyx_k_quant_method[] = "quant_method";
static const char __pyx_k_scipy_signal[] = "scipy.signal";
static const char __pyx_k_search_index[] = "search_index";
static const char __pyx_k_search_value[] = "search_value";
static const char __pyx_k_searchsorted[] = "searchsorted";
static const char __pyx_k_sorted_peaks[] = "sorted_peaks";
static const char __pyx_k_calc_start_mz[] = "calc_start_mz";
static const char __pyx_k_data_is_empty[] = "data is empty";
static const char __pyx_k_fitting_error[] = "fitting error";
static const char __pyx_k_fragment_scan[] = "fragment_scan";
static const char __pyx_k_precursor_ppm[] = "precursor_ppm";
static const char __pyx_k_reporter_mode[] = "reporter_mode";
static const char __pyx_k_skip_isotopes[] = "skip_isotopes";
static const char __pyx_k_sorted_peaks2[] = "sorted_peaks2";
static const char __pyx_k_df_empty_index[] = "df_empty_index";
static const char __pyx_k_isotope_offset[] = "isotope_offset";
static const char __pyx_k_last_precursor[] = "last_precursor";
static const char __pyx_k_peak_residuals[] = "peak_residuals";
static const char __pyx_k_peak_width_end[] = "peak_width_end";
static const char __pyx_k_pyquant_cpeaks[] = "pyquant.cpeaks";
static const char __pyx_k_ydata_original[] = "ydata_original";
static const char __pyx_k_fitting_results[] = "fitting results";
static const char __pyx_k_micro_envelopes[] = "micro_envelopes";
static const char __pyx_k_pattern2_1_loss[] = "pattern2.1 loss";
static const char __pyx_k_pattern2_2_loss[] = "pattern2.2 loss";
static const char __pyx_k_amplitude_filter[] = "amplitude_filter";
static const char __pyx_k_contaminant_loss[] = "contaminant loss";
static const char __pyx_k_empty_start_info[] = "empty start info";
static const char __pyx_k_guess_and_bounds[] = "guess and bounds";
static const char __pyx_k_peak_width_start[] = "peak_width_start";
static const char __pyx_k_gaussian_filter1d[] = "gaussian_filter1d";
static const char __pyx_k_scipy_interpolate[] = "scipy.interpolate";
static const char __pyx_k_contaminant_search[] = "contaminant_search";
static const char __pyx_k_find_nearest_index[] = "find_nearest_index";
static const char __pyx_k_isotopologue_limit[] = "isotopologue_limit";
static const char __pyx_k_find_nearest_indices[] = "find_nearest_indices";
static const char __pyx_k_scipy_ndimage_filters[] = "scipy.ndimage.filters";
static const char __pyx_k_findMicro_locals_lambda[] = "findMicro.<locals>.<lambda>";
static const char __pyx_k_unable_to_find_start_ion[] = "unable to find start ion";
static const char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static const char __pyx_k_pythomics_proteomics_config[] = "pythomics.proteomics.config";
static const char __pyx_k_opt_conda_conda_bld_pyquant_ms[] = "/opt/conda/conda-bld/pyquant-ms_1475052647696/work/pyquant-ms-0.1.42/pyquant/cpeaks.pyx";
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_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous";
static const char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short.";
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2;
static PyObject *__pyx_kp_s_L_BFGS_B;
static PyObject *__pyx_n_s_NEUTRON;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_OrderedDict;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_s_SLSQP;
static PyObject *__pyx_n_s_TNC;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s__18;
static PyObject *__pyx_kp_s__20;
static PyObject *__pyx_kp_s__23;
static PyObject *__pyx_n_s_abs;
static PyObject *__pyx_n_s_amplitude_filter;
static PyObject *__pyx_n_s_analyzing;
static PyObject *__pyx_n_s_any;
static PyObject *__pyx_n_s_argmax;
static PyObject *__pyx_n_s_argrelmax;
static PyObject *__pyx_n_s_argrelmin;
static PyObject *__pyx_n_s_argsort;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_attrgetter;
static PyObject *__pyx_n_s_average;
static PyObject *__pyx_n_s_axis;
static PyObject *__pyx_n_s_becomes;
static PyObject *__pyx_kp_s_best;
static PyObject *__pyx_kp_s_best_fit;
static PyObject *__pyx_n_s_bic;
static PyObject *__pyx_n_s_bigauss_fit;
static PyObject *__pyx_n_s_bigauss_func;
static PyObject *__pyx_n_s_bigauss_jac;
static PyObject *__pyx_n_s_bounds;
static PyObject *__pyx_n_s_calc_start_mz;
static PyObject *__pyx_n_s_centroid;
static PyObject *__pyx_n_s_charge;
static PyObject *__pyx_kp_s_checking;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_concatenate;
static PyObject *__pyx_n_s_constant;
static PyObject *__pyx_n_s_contains_rt;
static PyObject *__pyx_kp_s_contaminant_loss;
static PyObject *__pyx_n_s_contaminant_search;
static PyObject *__pyx_n_s_convolve;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_kp_s_data_is_empty;
static PyObject *__pyx_n_s_debug;
static PyObject *__pyx_n_s_deepcopy;
static PyObject *__pyx_n_s_df_empty_index;
static PyObject *__pyx_n_s_diff;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_kp_s_empty_start_info;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_envelope;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_exp;
static PyObject *__pyx_n_s_fabs;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_filter;
static PyObject *__pyx_kp_s_final_peaks;
static PyObject *__pyx_n_s_findAllPeaks;
static PyObject *__pyx_n_s_findMicro;
static PyObject *__pyx_n_s_findMicro_locals_lambda;
static PyObject *__pyx_n_s_find_nearest;
static PyObject *__pyx_n_s_find_nearest_index;
static PyObject *__pyx_n_s_find_nearest_indices;
static PyObject *__pyx_n_s_fit;
static PyObject *__pyx_kp_s_fitting_error;
static PyObject *__pyx_kp_s_fitting_results;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_format_exc;
static PyObject *__pyx_kp_s_found;
static PyObject *__pyx_n_s_fragment_scan;
static PyObject *__pyx_n_s_ftol;
static PyObject *__pyx_n_s_fun;
static PyObject *__pyx_n_s_gauss_func;
static PyObject *__pyx_n_s_gauss_jac;
static PyObject *__pyx_n_s_gaussian_filter1d;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_gradient;
static PyObject *__pyx_n_s_guess;
static PyObject *__pyx_kp_s_guess_and_bounds;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_idx;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_n_s_inf;
static PyObject *__pyx_n_s_int;
static PyObject *__pyx_n_s_int2;
static PyObject *__pyx_n_s_int_val;
static PyObject *__pyx_n_s_integrate;
static PyObject *__pyx_n_s_interp1d;
static PyObject *__pyx_n_s_intersection;
static PyObject *__pyx_n_s_isnan;
static PyObject *__pyx_n_s_isotope;
static PyObject *__pyx_n_s_isotope_offset;
static PyObject *__pyx_n_s_isotope_ppm;
static PyObject *__pyx_n_s_isotope_ppms;
static PyObject *__pyx_n_s_isotopologue_limit;
static PyObject *__pyx_n_s_itemgetter;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_jac;
static PyObject *__pyx_n_s_kaiser;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_label;
static PyObject *__pyx_n_s_last_precursor;
static PyObject *__pyx_n_s_left;
static PyObject *__pyx_kp_s_left_is;
static PyObject *__pyx_n_s_log;
static PyObject *__pyx_n_s_lr;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_mz;
static PyObject *__pyx_n_s_max_peaks;
static PyObject *__pyx_n_s_maxiter;
static PyObject *__pyx_n_s_measured_mz;
static PyObject *__pyx_n_s_method;
static PyObject *__pyx_n_s_micro_envelopes;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_min_dist;
static PyObject *__pyx_n_s_minima;
static PyObject *__pyx_n_s_minimize;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_mrm;
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_x;
static PyObject *__pyx_n_s_new_y;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_n_s_observed;
static PyObject *__pyx_n_s_offset;
static PyObject *__pyx_n_s_operator;
static PyObject *__pyx_kp_s_opt_conda_conda_bld_pyquant_ms;
static PyObject *__pyx_n_s_optimize;
static PyObject *__pyx_n_s_options;
static PyObject *__pyx_n_s_order;
static PyObject *__pyx_n_s_out;
static PyObject *__pyx_n_s_params;
static PyObject *__pyx_kp_s_pattern2_1_loss;
static PyObject *__pyx_kp_s_pattern2_2_loss;
static PyObject *__pyx_n_s_peak;
static PyObject *__pyx_n_s_peak_index;
static PyObject *__pyx_n_s_peak_mean;
static PyObject *__pyx_n_s_peak_residuals;
static PyObject *__pyx_n_s_peak_width_end;
static PyObject *__pyx_n_s_peak_width_start;
static PyObject *__pyx_n_s_peaks;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_ppm;
static PyObject *__pyx_n_s_ppms;
static PyObject *__pyx_n_s_precursor_ppm;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_pyquant_cpeaks;
static PyObject *__pyx_n_s_pythomics_proteomics_config;
static PyObject *__pyx_n_s_quant_method;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_reporter_mode;
static PyObject *__pyx_n_s_ret_dict;
static PyObject *__pyx_n_s_right;
static PyObject *__pyx_kp_s_right_is;
static PyObject *__pyx_n_s_rt_peak;
static PyObject *__pyx_n_s_same;
static PyObject *__pyx_n_s_scipy;
static PyObject *__pyx_n_s_scipy_interpolate;
static PyObject *__pyx_n_s_scipy_ndimage_filters;
static PyObject *__pyx_n_s_scipy_signal;
static PyObject *__pyx_n_s_search_index;
static PyObject *__pyx_n_s_search_value;
static PyObject *__pyx_n_s_searchsorted;
static PyObject *__pyx_n_s_side;
static PyObject *__pyx_n_s_sign;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_skip_isotopes;
static PyObject *__pyx_n_s_snr;
static PyObject *__pyx_n_s_sort;
static PyObject *__pyx_n_s_sorted;
static PyObject *__pyx_n_s_sorted_peaks;
static PyObject *__pyx_n_s_sorted_peaks2;
static PyObject *__pyx_n_s_spacing;
static PyObject *__pyx_n_s_sqrt;
static PyObject *__pyx_n_s_start_mz;
static PyObject *__pyx_n_s_std;
static PyObject *__pyx_n_s_stderr;
static PyObject *__pyx_n_s_success;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_theo_dist;
static PyObject *__pyx_n_s_theo_mz;
static PyObject *__pyx_n_s_theoretical;
static PyObject *__pyx_n_s_tol;
static PyObject *__pyx_n_s_tolerance;
static PyObject *__pyx_n_s_tolist;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_n_s_transpose;
static PyObject *__pyx_kp_s_unable_to_find_start_ion;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_v;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_weights;
static PyObject *__pyx_n_s_where;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_xdata;
static PyObject *__pyx_n_s_xrange;
static PyObject *__pyx_n_s_y;
static PyObject *__pyx_n_s_ydata;
static PyObject *__pyx_n_s_ydata_original;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_pf_7pyquant_6cpeaks_gauss_ndim(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_2gauss_func(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_4bigauss_jac(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_6gauss_jac(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_8bigauss_ndim(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_10bigauss_func(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_12fixedMeanFit(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, int __pyx_v_peak_index, PyObject *__pyx_v_debug); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_14fixedMeanFit2(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, int __pyx_v_peak_index, PyObject *__pyx_v_debug); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_16basin_stepper(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_args); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_18findAllPeaks(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata_original, float __pyx_v_min_dist, PyObject *__pyx_v_filter, PyObject *__pyx_v_bigauss_fit, PyObject *__pyx_v_rt_peak, PyObject *__pyx_v_mrm, int __pyx_v_max_peaks, PyObject *__pyx_v_debug, PyObject *__pyx_v_peak_width_start, PyObject *__pyx_v_snr, PyObject *__pyx_v_amplitude_filter, PyObject *__pyx_v_peak_width_end); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_20get_ppm(CYTHON_UNUSED PyObject *__pyx_self, float __pyx_v_theoretical, float __pyx_v_observed); /* proto */
static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_22findMicro(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, PyObject *__pyx_v_pos, PyObject *__pyx_v_ppm, PyObject *__pyx_v_start_mz, PyObject *__pyx_v_calc_start_mz, PyObject *__pyx_v_isotope, PyObject *__pyx_v_spacing, CYTHON_UNUSED PyObject *__pyx_v_quant_method, PyObject *__pyx_v_fragment_scan, PyObject *__pyx_v_centroid); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_24find_nearest(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_26find_nearest_index(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_28find_nearest_indices(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_7pyquant_6cpeaks_30findEnvelope(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, PyObject *__pyx_v_measured_mz, PyObject *__pyx_v_theo_mz, PyObject *__pyx_v_max_mz, PyObject *__pyx_v_precursor_ppm, PyObject *__pyx_v_isotope_ppm, PyObject *__pyx_v_isotope_ppms, PyObject *__pyx_v_charge, PyObject *__pyx_v_debug, PyObject *__pyx_v_isotope_offset, PyObject *__pyx_v_isotopologue_limit, PyObject *__pyx_v_theo_dist, PyObject *__pyx_v_label, PyObject *__pyx_v_skip_isotopes, PyObject *__pyx_v_last_precursor, PyObject *__pyx_v_quant_method, PyObject *__pyx_v_reporter_mode, PyObject *__pyx_v_fragment_scan, PyObject *__pyx_v_centroid, PyObject *__pyx_v_contaminant_search); /* 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_tp_new_7pyquant_6cpeaks___pyx_scope_struct__findMicro(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0};
static PyObject *__pyx_float_0_;
static PyObject *__pyx_float_0_0;
static PyObject *__pyx_float_0_1;
static PyObject *__pyx_float_0_9;
static PyObject *__pyx_float_1_0;
static PyObject *__pyx_float_2_5;
static PyObject *__pyx_float_0_05;
static PyObject *__pyx_float_1_01;
static PyObject *__pyx_float_1eneg_20;
static PyObject *__pyx_float_1000000_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_10;
static PyObject *__pyx_int_12;
static PyObject *__pyx_int_14;
static PyObject *__pyx_int_1000;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_neg_2;
static PyObject *__pyx_slice_;
static PyObject *__pyx_slice__2;
static PyObject *__pyx_slice__3;
static PyObject *__pyx_slice__4;
static PyObject *__pyx_slice__5;
static PyObject *__pyx_slice__6;
static PyObject *__pyx_slice__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__13;
static PyObject *__pyx_slice__14;
static PyObject *__pyx_slice__15;
static PyObject *__pyx_slice__16;
static PyObject *__pyx_slice__19;
static PyObject *__pyx_slice__24;
static PyObject *__pyx_slice__26;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_codeobj__40;
static PyObject *__pyx_codeobj__42;
static PyObject *__pyx_codeobj__44;
static PyObject *__pyx_codeobj__46;

/* "pyquant/cpeaks.pyx":15
 * from pythomics.proteomics.config import NEUTRON
 * 
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):             # <<<<<<<<<<<<<<
 *     for i,j in zip(res, bnds):
 *         if j[0] is not None and i < j[0]:
 */

static int __pyx_f_7pyquant_6cpeaks_within_bounds(PyArrayObject *__pyx_v_res, PyArrayObject *__pyx_v_bnds) {
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_j = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bnds;
  __Pyx_Buffer __pyx_pybuffer_bnds;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_res;
  __Pyx_Buffer __pyx_pybuffer_res;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  __Pyx_RefNannySetupContext("within_bounds", 0);
  __pyx_pybuffer_res.pybuffer.buf = NULL;
  __pyx_pybuffer_res.refcount = 0;
  __pyx_pybuffernd_res.data = NULL;
  __pyx_pybuffernd_res.rcbuffer = &__pyx_pybuffer_res;
  __pyx_pybuffer_bnds.pybuffer.buf = NULL;
  __pyx_pybuffer_bnds.refcount = 0;
  __pyx_pybuffernd_bnds.data = NULL;
  __pyx_pybuffernd_bnds.rcbuffer = &__pyx_pybuffer_bnds;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_res.rcbuffer->pybuffer, (PyObject*)__pyx_v_res, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 15, __pyx_L1_error)
  }
  __pyx_pybuffernd_res.diminfo[0].strides = __pyx_pybuffernd_res.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_res.diminfo[0].shape = __pyx_pybuffernd_res.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer, (PyObject*)__pyx_v_bnds, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 15, __pyx_L1_error)
  }
  __pyx_pybuffernd_bnds.diminfo[0].strides = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bnds.diminfo[0].shape = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bnds.diminfo[1].strides = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bnds.diminfo[1].shape = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.shape[1];

  /* "pyquant/cpeaks.pyx":16
 * 
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):
 *     for i,j in zip(res, bnds):             # <<<<<<<<<<<<<<
 *         if j[0] is not None and i < j[0]:
 *             return 0
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_res));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_res));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_res));
  __Pyx_INCREF(((PyObject *)__pyx_v_bnds));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_bnds));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_bnds));
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 16, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 16, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 16, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_4(__pyx_t_1);
      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, 16, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 16, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      #else
      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 16, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 16, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 16, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
      __pyx_t_8 = NULL;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 16, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pyquant/cpeaks.pyx":17
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):
 *     for i,j in zip(res, bnds):
 *         if j[0] is not None and i < j[0]:             # <<<<<<<<<<<<<<
 *             return 0
 *         if j[1] is not None and i > j[1]:
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = (__pyx_t_2 != Py_None);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_11 = (__pyx_t_10 != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_9 = __pyx_t_11;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 17, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 17, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __pyx_t_11;
    __pyx_L8_bool_binop_done:;
    if (__pyx_t_9) {

      /* "pyquant/cpeaks.pyx":18
 *     for i,j in zip(res, bnds):
 *         if j[0] is not None and i < j[0]:
 *             return 0             # <<<<<<<<<<<<<<
 *         if j[1] is not None and i > j[1]:
 *             return 0
 */
      __pyx_r = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "pyquant/cpeaks.pyx":17
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):
 *     for i,j in zip(res, bnds):
 *         if j[0] is not None and i < j[0]:             # <<<<<<<<<<<<<<
 *             return 0
 *         if j[1] is not None and i > j[1]:
 */
    }

    /* "pyquant/cpeaks.pyx":19
 *         if j[0] is not None and i < j[0]:
 *             return 0
 *         if j[1] is not None and i > j[1]:             # <<<<<<<<<<<<<<
 *             return 0
 *     return 1
 */
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_j, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 19, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = (__pyx_t_6 != Py_None);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_10 = (__pyx_t_11 != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_9 = __pyx_t_10;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_j, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 19, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_i, __pyx_t_6, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 19, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_9 = __pyx_t_10;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_9) {

      /* "pyquant/cpeaks.pyx":20
 *             return 0
 *         if j[1] is not None and i > j[1]:
 *             return 0             # <<<<<<<<<<<<<<
 *     return 1
 * 
 */
      __pyx_r = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "pyquant/cpeaks.pyx":19
 *         if j[0] is not None and i < j[0]:
 *             return 0
 *         if j[1] is not None and i > j[1]:             # <<<<<<<<<<<<<<
 *             return 0
 *     return 1
 */
    }

    /* "pyquant/cpeaks.pyx":16
 * 
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):
 *     for i,j in zip(res, bnds):             # <<<<<<<<<<<<<<
 *         if j[0] is not None and i < j[0]:
 *             return 0
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":21
 *         if j[1] is not None and i > j[1]:
 *             return 0
 *     return 1             # <<<<<<<<<<<<<<
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] gauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float std):
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":15
 * from pythomics.proteomics.config import NEUTRON
 * 
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):             # <<<<<<<<<<<<<<
 *     for i,j in zip(res, bnds):
 *         if j[0] is not None and i < j[0]:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_res.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_WriteUnraisable("pyquant.cpeaks.within_bounds", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_res.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_j);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":23
 *     return 1
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] gauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float std):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = amp*np.exp(-(x - mu)**2/(2*std**2))
 *     return y
 */

static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss(PyArrayObject *__pyx_v_x, float __pyx_v_amp, float __pyx_v_mu, float __pyx_v_std) {
  PyArrayObject *__pyx_v_y = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("gauss", 0);
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 23, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":24
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] gauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float std):
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = amp*np.exp(-(x - mu)**2/(2*std**2))             # <<<<<<<<<<<<<<
 *     return y
 * 
 */
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Subtract(((PyObject *)__pyx_v_x), __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Power(__pyx_t_5, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyFloat_FromDouble((2.0 * powf(__pyx_v_std, 2.0))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 24, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_y = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_y.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 24, __pyx_L1_error)
    } else {__pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_y = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":25
 * cdef np.ndarray[FLOAT_t, ndim=1] gauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float std):
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = amp*np.exp(-(x - mu)**2/(2*std**2))
 *     return y             # <<<<<<<<<<<<<<
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] gauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_y));
  __pyx_r = ((PyArrayObject *)__pyx_v_y);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":23
 *     return 1
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] gauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float std):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = amp*np.exp(-(x - mu)**2/(2*std**2))
 *     return y
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_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_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_y);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":27
 *     return y
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] gauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] amps
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_1gauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss_ndim(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_amps = 0;
  PyArrayObject *__pyx_v_mus = 0;
  PyArrayObject *__pyx_v_sigmas = 0;
  PyArrayObject *__pyx_v_data = 0;
  PyObject *__pyx_v_amp = NULL;
  PyObject *__pyx_v_mu = NULL;
  PyObject *__pyx_v_sigma = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_amps;
  __Pyx_Buffer __pyx_pybuffer_amps;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
  __Pyx_Buffer __pyx_pybuffer_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_mus;
  __Pyx_Buffer __pyx_pybuffer_mus;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_sigmas;
  __Pyx_Buffer __pyx_pybuffer_sigmas;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  PyArrayObject *__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;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyArrayObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  PyObject *(*__pyx_t_17)(PyObject *);
  float __pyx_t_18;
  float __pyx_t_19;
  float __pyx_t_20;
  __Pyx_RefNannySetupContext("gauss_ndim", 0);
  __pyx_pybuffer_amps.pybuffer.buf = NULL;
  __pyx_pybuffer_amps.refcount = 0;
  __pyx_pybuffernd_amps.data = NULL;
  __pyx_pybuffernd_amps.rcbuffer = &__pyx_pybuffer_amps;
  __pyx_pybuffer_mus.pybuffer.buf = NULL;
  __pyx_pybuffer_mus.refcount = 0;
  __pyx_pybuffernd_mus.data = NULL;
  __pyx_pybuffernd_mus.rcbuffer = &__pyx_pybuffer_mus;
  __pyx_pybuffer_sigmas.pybuffer.buf = NULL;
  __pyx_pybuffer_sigmas.refcount = 0;
  __pyx_pybuffernd_sigmas.data = NULL;
  __pyx_pybuffernd_sigmas.rcbuffer = &__pyx_pybuffer_sigmas;
  __pyx_pybuffer_data.pybuffer.buf = NULL;
  __pyx_pybuffer_data.refcount = 0;
  __pyx_pybuffernd_data.data = NULL;
  __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 27, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 27, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":31
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmas
 *     amps, mus, sigmas = params[::3], params[1::3], params[2::3]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma in zip(amps, mus, sigmas):
 */
  __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice_); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __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, 31, __pyx_L1_error)
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __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, 31, __pyx_L1_error)
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 31, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_amps.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_amps.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_amps.rcbuffer->pybuffer, (PyObject*)__pyx_v_amps, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_amps.diminfo[0].strides = __pyx_pybuffernd_amps.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_amps.diminfo[0].shape = __pyx_pybuffernd_amps.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 31, __pyx_L1_error)
  }
  __pyx_t_4 = 0;
  __pyx_v_amps = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mus.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mus.rcbuffer->pybuffer, (PyObject*)__pyx_v_mus, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
      }
    }
    __pyx_pybuffernd_mus.diminfo[0].strides = __pyx_pybuffernd_mus.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mus.diminfo[0].shape = __pyx_pybuffernd_mus.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 31, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_mus = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmas.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmas.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmas.rcbuffer->pybuffer, (PyObject*)__pyx_v_sigmas, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_sigmas.diminfo[0].strides = __pyx_pybuffernd_sigmas.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_sigmas.diminfo[0].shape = __pyx_pybuffernd_sigmas.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 31, __pyx_L1_error)
  }
  __pyx_t_10 = 0;
  __pyx_v_sigmas = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":32
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmas
 *     amps, mus, sigmas = params[::3], params[1::3], params[2::3]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))             # <<<<<<<<<<<<<<
 *     for amp, mu, sigma in zip(amps, mus, sigmas):
 *         data += gauss(xdata, amp, mu, sigma)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 32, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_12 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_12) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL;
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 32, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 32, __pyx_L1_error)
    } else {__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_14 = 0;
  __pyx_v_data = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":33
 *     amps, mus, sigmas = params[::3], params[1::3], params[2::3]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma in zip(amps, mus, sigmas):             # <<<<<<<<<<<<<<
 *         data += gauss(xdata, amp, mu, sigma)
 *     return data
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_amps));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_amps));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_amps));
  __Pyx_INCREF(((PyObject *)__pyx_v_mus));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_mus));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_mus));
  __Pyx_INCREF(((PyObject *)__pyx_v_sigmas));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_sigmas));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_sigmas));
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_11 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_11 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_15 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 33, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 33, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 33, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_15(__pyx_t_3);
      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, 33, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 33, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_12 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_13 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_12 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_12);
      #else
      __pyx_t_13 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_12 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 33, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_13 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_13)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_13);
      index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 2; __pyx_t_12 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_12)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_12);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 3) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
      __pyx_t_17 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_17 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 33, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_amp, __pyx_t_13);
    __pyx_t_13 = 0;
    __Pyx_XDECREF_SET(__pyx_v_mu, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_sigma, __pyx_t_12);
    __pyx_t_12 = 0;

    /* "pyquant/cpeaks.pyx":34
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma in zip(amps, mus, sigmas):
 *         data += gauss(xdata, amp, mu, sigma)             # <<<<<<<<<<<<<<
 *     return data
 * 
 */
    __pyx_t_18 = __pyx_PyFloat_AsFloat(__pyx_v_amp); if (unlikely((__pyx_t_18 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 34, __pyx_L1_error)
    __pyx_t_19 = __pyx_PyFloat_AsFloat(__pyx_v_mu); if (unlikely((__pyx_t_19 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 34, __pyx_L1_error)
    __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_v_sigma); if (unlikely((__pyx_t_20 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 34, __pyx_L1_error)
    __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_gauss(((PyArrayObject *)__pyx_v_xdata), __pyx_t_18, __pyx_t_19, __pyx_t_20)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_12 = PyNumber_InPlaceAdd(((PyObject *)__pyx_v_data), __pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 34, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 34, __pyx_L1_error)
    __pyx_t_14 = ((PyArrayObject *)__pyx_t_12);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
      __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_5 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
        }
      }
      __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 34, __pyx_L1_error)
    }
    __pyx_t_14 = 0;
    __Pyx_DECREF_SET(__pyx_v_data, ((PyArrayObject *)__pyx_t_12));
    __pyx_t_12 = 0;

    /* "pyquant/cpeaks.pyx":33
 *     amps, mus, sigmas = params[::3], params[1::3], params[2::3]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma in zip(amps, mus, sigmas):             # <<<<<<<<<<<<<<
 *         data += gauss(xdata, amp, mu, sigma)
 *     return data
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":35
 *     for amp, mu, sigma in zip(amps, mus, sigmas):
 *         data += gauss(xdata, amp, mu, sigma)
 *     return data             # <<<<<<<<<<<<<<
 * 
 * cpdef float gauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_data));
  __pyx_r = ((PyArrayObject *)__pyx_v_data);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":27
 *     return y
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] gauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] amps
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 */

  /* 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_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_16);
  { 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_amps.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmas.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_amps.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmas.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_amps);
  __Pyx_XDECREF((PyObject *)__pyx_v_mus);
  __Pyx_XDECREF((PyObject *)__pyx_v_sigmas);
  __Pyx_XDECREF((PyObject *)__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_amp);
  __Pyx_XDECREF(__pyx_v_mu);
  __Pyx_XDECREF(__pyx_v_sigma);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_1gauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_1gauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gauss_ndim (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_params,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_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gauss_ndim", 1, 2, 2, 1); __PYX_ERR(0, 27, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gauss_ndim") < 0)) __PYX_ERR(0, 27, __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_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_params = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("gauss_ndim", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 27, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 27, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_params), __pyx_ptype_5numpy_ndarray, 1, "params", 0))) __PYX_ERR(0, 27, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_gauss_ndim(__pyx_self, __pyx_v_xdata, __pyx_v_params);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_gauss_ndim(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("gauss_ndim", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 27, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 27, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_gauss_ndim(__pyx_v_xdata, __pyx_v_params, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":37
 *     return data
 * 
 * cpdef float gauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = gauss_ndim(xdata, guess)
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_3gauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_gauss_func(PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_data = 0;
  float __pyx_v_residual;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
  __Pyx_Buffer __pyx_pybuffer_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  float __pyx_t_3;
  __Pyx_RefNannySetupContext("gauss_func", 0);
  __pyx_pybuffer_data.pybuffer.buf = NULL;
  __pyx_pybuffer_data.refcount = 0;
  __pyx_pybuffernd_data.data = NULL;
  __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_v_guess, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":38
 * 
 * cpdef float gauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = gauss_ndim(xdata, guess)             # <<<<<<<<<<<<<<
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 *     # residual sum of squares for this data.
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_gauss_ndim(((PyArrayObject *)__pyx_v_xdata), ((PyArrayObject *)__pyx_v_guess), 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 38, __pyx_L1_error)
    } else {__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_data = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":41
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 *     # residual sum of squares for this data.
 *     cdef float residual = sum((ydata-data)**2)             # <<<<<<<<<<<<<<
 *     return residual
 * 
 */
  __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_ydata), ((PyObject *)__pyx_v_data)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __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 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_residual = __pyx_t_3;

  /* "pyquant/cpeaks.pyx":42
 *     # residual sum of squares for this data.
 *     cdef float residual = sum((ydata-data)**2)
 *     return residual             # <<<<<<<<<<<<<<
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] bigauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):
 */
  __pyx_r = __pyx_v_residual;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":37
 *     return data
 * 
 * cpdef float gauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = gauss_ndim(xdata, guess)
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  { 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_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_WriteUnraisable("pyquant.cpeaks.gauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_data);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_3gauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_3gauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_guess = 0;
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gauss_func (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_guess,&__pyx_n_s_xdata,&__pyx_n_s_ydata,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_guess)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xdata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gauss_func", 1, 3, 3, 1); __PYX_ERR(0, 37, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gauss_func", 1, 3, 3, 2); __PYX_ERR(0, 37, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gauss_func") < 0)) __PYX_ERR(0, 37, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_guess = ((PyArrayObject *)values[0]);
    __pyx_v_xdata = ((PyArrayObject *)values[1]);
    __pyx_v_ydata = ((PyArrayObject *)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("gauss_func", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 37, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_guess), __pyx_ptype_5numpy_ndarray, 1, "guess", 0))) __PYX_ERR(0, 37, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 37, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 37, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_2gauss_func(__pyx_self, __pyx_v_guess, __pyx_v_xdata, __pyx_v_ydata);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_2gauss_func(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("gauss_func", 0);
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_v_guess, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_gauss_func(__pyx_v_guess, __pyx_v_xdata, __pyx_v_ydata, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":44
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] bigauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=2] jac
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx, ly, rx, ry
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_5bigauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss_jac(PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_jac = 0;
  PyArrayObject *__pyx_v_lx = 0;
  PyArrayObject *__pyx_v_ly = 0;
  PyArrayObject *__pyx_v_rx = 0;
  PyArrayObject *__pyx_v_ry = 0;
  float __pyx_v_amp;
  float __pyx_v_mu;
  float __pyx_v_stdl;
  float __pyx_v_stdr;
  float __pyx_v_sigma1;
  float __pyx_v_sigma2;
  int __pyx_v_i;
  PyObject *__pyx_v_exp_term = NULL;
  PyObject *__pyx_v_amp_exp_term = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_prefix = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_jac;
  __Pyx_Buffer __pyx_pybuffer_jac;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lx;
  __Pyx_Buffer __pyx_pybuffer_lx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ly;
  __Pyx_Buffer __pyx_pybuffer_ly;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rx;
  __Pyx_Buffer __pyx_pybuffer_rx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ry;
  __Pyx_Buffer __pyx_pybuffer_ry;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  npy_intp __pyx_t_11;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  __pyx_t_7pyquant_6cpeaks_FLOAT_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  __Pyx_RefNannySetupContext("bigauss_jac", 0);
  __pyx_pybuffer_jac.pybuffer.buf = NULL;
  __pyx_pybuffer_jac.refcount = 0;
  __pyx_pybuffernd_jac.data = NULL;
  __pyx_pybuffernd_jac.rcbuffer = &__pyx_pybuffer_jac;
  __pyx_pybuffer_lx.pybuffer.buf = NULL;
  __pyx_pybuffer_lx.refcount = 0;
  __pyx_pybuffernd_lx.data = NULL;
  __pyx_pybuffernd_lx.rcbuffer = &__pyx_pybuffer_lx;
  __pyx_pybuffer_ly.pybuffer.buf = NULL;
  __pyx_pybuffer_ly.refcount = 0;
  __pyx_pybuffernd_ly.data = NULL;
  __pyx_pybuffernd_ly.rcbuffer = &__pyx_pybuffer_ly;
  __pyx_pybuffer_rx.pybuffer.buf = NULL;
  __pyx_pybuffer_rx.refcount = 0;
  __pyx_pybuffernd_rx.data = NULL;
  __pyx_pybuffernd_rx.rcbuffer = &__pyx_pybuffer_rx;
  __pyx_pybuffer_ry.pybuffer.buf = NULL;
  __pyx_pybuffer_ry.refcount = 0;
  __pyx_pybuffernd_ry.data = NULL;
  __pyx_pybuffernd_ry.rcbuffer = &__pyx_pybuffer_ry;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":49
 *     cdef float amp, mu, stdl, stdr, sigma1, sigma2
 *     cdef int i
 *     jac = np.zeros((params.shape[0], 1))             # <<<<<<<<<<<<<<
 *     for i in xrange(params.shape[0]):
 *         if i%4 == 0:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_Py_intptr_t((__pyx_v_params->dimensions[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
  __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 49, __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_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 49, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_jac.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_jac.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_jac.rcbuffer->pybuffer, (PyObject*)__pyx_v_jac, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_jac.diminfo[0].strides = __pyx_pybuffernd_jac.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_jac.diminfo[0].shape = __pyx_pybuffernd_jac.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_jac.diminfo[1].strides = __pyx_pybuffernd_jac.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_jac.diminfo[1].shape = __pyx_pybuffernd_jac.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 49, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_jac = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":50
 *     cdef int i
 *     jac = np.zeros((params.shape[0], 1))
 *     for i in xrange(params.shape[0]):             # <<<<<<<<<<<<<<
 *         if i%4 == 0:
 *             amp = params[i]
 */
  __pyx_t_11 = (__pyx_v_params->dimensions[0]);
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_11; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pyquant/cpeaks.pyx":51
 *     jac = np.zeros((params.shape[0], 1))
 *     for i in xrange(params.shape[0]):
 *         if i%4 == 0:             # <<<<<<<<<<<<<<
 *             amp = params[i]
 *         elif i%4 == 1:
 */
    __pyx_t_12 = ((__Pyx_mod_long(__pyx_v_i, 4) == 0) != 0);
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":52
 *     for i in xrange(params.shape[0]):
 *         if i%4 == 0:
 *             amp = params[i]             # <<<<<<<<<<<<<<
 *         elif i%4 == 1:
 *             mu = params[i]
 */
      __pyx_t_13 = __pyx_v_i;
      __pyx_t_14 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_pybuffernd_params.diminfo[0].shape;
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_pybuffernd_params.diminfo[0].shape)) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 52, __pyx_L1_error)
      }
      __pyx_v_amp = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_params.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_params.diminfo[0].strides));

      /* "pyquant/cpeaks.pyx":51
 *     jac = np.zeros((params.shape[0], 1))
 *     for i in xrange(params.shape[0]):
 *         if i%4 == 0:             # <<<<<<<<<<<<<<
 *             amp = params[i]
 *         elif i%4 == 1:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":53
 *         if i%4 == 0:
 *             amp = params[i]
 *         elif i%4 == 1:             # <<<<<<<<<<<<<<
 *             mu = params[i]
 *         elif i%4 == 2:
 */
    __pyx_t_12 = ((__Pyx_mod_long(__pyx_v_i, 4) == 1) != 0);
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":54
 *             amp = params[i]
 *         elif i%4 == 1:
 *             mu = params[i]             # <<<<<<<<<<<<<<
 *         elif i%4 == 2:
 *             stdl = params[i]
 */
      __pyx_t_15 = __pyx_v_i;
      __pyx_t_14 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_pybuffernd_params.diminfo[0].shape;
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_pybuffernd_params.diminfo[0].shape)) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 54, __pyx_L1_error)
      }
      __pyx_v_mu = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_params.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_params.diminfo[0].strides));

      /* "pyquant/cpeaks.pyx":53
 *         if i%4 == 0:
 *             amp = params[i]
 *         elif i%4 == 1:             # <<<<<<<<<<<<<<
 *             mu = params[i]
 *         elif i%4 == 2:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":55
 *         elif i%4 == 1:
 *             mu = params[i]
 *         elif i%4 == 2:             # <<<<<<<<<<<<<<
 *             stdl = params[i]
 *         elif i%4 == 3:
 */
    __pyx_t_12 = ((__Pyx_mod_long(__pyx_v_i, 4) == 2) != 0);
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":56
 *             mu = params[i]
 *         elif i%4 == 2:
 *             stdl = params[i]             # <<<<<<<<<<<<<<
 *         elif i%4 == 3:
 *             stdr = params[i]
 */
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_14 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_pybuffernd_params.diminfo[0].shape;
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_pybuffernd_params.diminfo[0].shape)) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 56, __pyx_L1_error)
      }
      __pyx_v_stdl = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_params.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_params.diminfo[0].strides));

      /* "pyquant/cpeaks.pyx":55
 *         elif i%4 == 1:
 *             mu = params[i]
 *         elif i%4 == 2:             # <<<<<<<<<<<<<<
 *             stdl = params[i]
 *         elif i%4 == 3:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":57
 *         elif i%4 == 2:
 *             stdl = params[i]
 *         elif i%4 == 3:             # <<<<<<<<<<<<<<
 *             stdr = params[i]
 *             sigma1 = stdl/1.177
 */
    __pyx_t_12 = ((__Pyx_mod_long(__pyx_v_i, 4) == 3) != 0);
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":58
 *             stdl = params[i]
 *         elif i%4 == 3:
 *             stdr = params[i]             # <<<<<<<<<<<<<<
 *             sigma1 = stdl/1.177
 *             sigma2 = stdr/1.177
 */
      __pyx_t_17 = __pyx_v_i;
      __pyx_t_14 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_params.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_params.diminfo[0].shape)) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 58, __pyx_L1_error)
      }
      __pyx_v_stdr = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_params.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_params.diminfo[0].strides));

      /* "pyquant/cpeaks.pyx":59
 *         elif i%4 == 3:
 *             stdr = params[i]
 *             sigma1 = stdl/1.177             # <<<<<<<<<<<<<<
 *             sigma2 = stdr/1.177
 *             lx = x[x<=mu]
 */
      __pyx_v_sigma1 = (__pyx_v_stdl / 1.177);

      /* "pyquant/cpeaks.pyx":60
 *             stdr = params[i]
 *             sigma1 = stdl/1.177
 *             sigma2 = stdr/1.177             # <<<<<<<<<<<<<<
 *             lx = x[x<=mu]
 *             ly = y[x<=mu]
 */
      __pyx_v_sigma2 = (__pyx_v_stdr / 1.177);

      /* "pyquant/cpeaks.pyx":61
 *             sigma1 = stdl/1.177
 *             sigma2 = stdr/1.177
 *             lx = x[x<=mu]             # <<<<<<<<<<<<<<
 *             ly = y[x<=mu]
 *             rx = x[x>mu]
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_1, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 61, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_x), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 61, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lx.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lx.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lx.rcbuffer->pybuffer, (PyObject*)__pyx_v_lx, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_lx.diminfo[0].strides = __pyx_pybuffernd_lx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lx.diminfo[0].shape = __pyx_pybuffernd_lx.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 61, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_lx, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":62
 *             sigma2 = stdr/1.177
 *             lx = x[x<=mu]
 *             ly = y[x<=mu]             # <<<<<<<<<<<<<<
 *             rx = x[x>mu]
 *             ry = y[x>mu]
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_1, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_y), __pyx_t_3); 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;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 62, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ly.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ly.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ly.rcbuffer->pybuffer, (PyObject*)__pyx_v_ly, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
        }
        __pyx_pybuffernd_ly.diminfo[0].strides = __pyx_pybuffernd_ly.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ly.diminfo[0].shape = __pyx_pybuffernd_ly.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 62, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_ly, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":63
 *             lx = x[x<=mu]
 *             ly = y[x<=mu]
 *             rx = x[x>mu]             # <<<<<<<<<<<<<<
 *             ry = y[x>mu]
 *             exp_term = np.exp(-((lx-mu)**2)/(2*sigma1**2))
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 63, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_x), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 63, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rx.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rx.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rx.rcbuffer->pybuffer, (PyObject*)__pyx_v_rx, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_rx.diminfo[0].strides = __pyx_pybuffernd_rx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rx.diminfo[0].shape = __pyx_pybuffernd_rx.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 63, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_rx, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":64
 *             ly = y[x<=mu]
 *             rx = x[x>mu]
 *             ry = y[x>mu]             # <<<<<<<<<<<<<<
 *             exp_term = np.exp(-((lx-mu)**2)/(2*sigma1**2))
 *             amp_exp_term = amp*exp_term
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_y), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 64, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ry.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ry.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ry.rcbuffer->pybuffer, (PyObject*)__pyx_v_ry, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
        }
        __pyx_pybuffernd_ry.diminfo[0].strides = __pyx_pybuffernd_ry.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ry.diminfo[0].shape = __pyx_pybuffernd_ry.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 64, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_ry, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":65
 *             rx = x[x>mu]
 *             ry = y[x>mu]
 *             exp_term = np.exp(-((lx-mu)**2)/(2*sigma1**2))             # <<<<<<<<<<<<<<
 *             amp_exp_term = amp*exp_term
 *             prefix = 2*amp_exp_term
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyNumber_Subtract(((PyObject *)__pyx_v_lx), __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyNumber_Power(__pyx_t_4, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma1, 2.0))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 65, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF_SET(__pyx_v_exp_term, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":66
 *             ry = y[x>mu]
 *             exp_term = np.exp(-((lx-mu)**2)/(2*sigma1**2))
 *             amp_exp_term = amp*exp_term             # <<<<<<<<<<<<<<
 *             prefix = 2*amp_exp_term
 *             # jac[i-3] += sum(prefix*(amp-ly*exp_term))
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_amp_exp_term, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyquant/cpeaks.pyx":67
 *             exp_term = np.exp(-((lx-mu)**2)/(2*sigma1**2))
 *             amp_exp_term = amp*exp_term
 *             prefix = 2*amp_exp_term             # <<<<<<<<<<<<<<
 *             # jac[i-3] += sum(prefix*(amp-ly*exp_term))
 *             jac[i-3, 0] += sum(-2*exp_term*(ly-amp_exp_term))
 */
      __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_prefix, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyquant/cpeaks.pyx":69
 *             prefix = 2*amp_exp_term
 *             # jac[i-3] += sum(prefix*(amp-ly*exp_term))
 *             jac[i-3, 0] += sum(-2*exp_term*(ly-amp_exp_term))             # <<<<<<<<<<<<<<
 *             jac[i-2, 0] += sum((-2*amp*(lx-mu)*exp_term*(ly-amp_exp_term))/(sigma1**2))
 *             jac[i-1, 0] += sum((-2*amp*((lx-mu)**2)*exp_term*(ly-amp_exp_term))/(sigma1**3))
 */
      __pyx_t_5 = PyNumber_Multiply(__pyx_int_neg_2, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_ly), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 69, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_20 = (__pyx_v_i - 3);
      __pyx_t_21 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 69, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_21, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":70
 *             # jac[i-3] += sum(prefix*(amp-ly*exp_term))
 *             jac[i-3, 0] += sum(-2*exp_term*(ly-amp_exp_term))
 *             jac[i-2, 0] += sum((-2*amp*(lx-mu)*exp_term*(ly-amp_exp_term))/(sigma1**2))             # <<<<<<<<<<<<<<
 *             jac[i-1, 0] += sum((-2*amp*((lx-mu)**2)*exp_term*(ly-amp_exp_term))/(sigma1**3))
 *             exp_term = np.exp(-((rx-mu)**2)/(2*sigma2**2))
 */
      __pyx_t_4 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Subtract(((PyObject *)__pyx_v_lx), __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_ly), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyFloat_FromDouble(powf(__pyx_v_sigma1, 2.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __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_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __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 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_22 = (__pyx_v_i - 2);
      __pyx_t_23 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_22 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_23 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 70, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_23, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":71
 *             jac[i-3, 0] += sum(-2*exp_term*(ly-amp_exp_term))
 *             jac[i-2, 0] += sum((-2*amp*(lx-mu)*exp_term*(ly-amp_exp_term))/(sigma1**2))
 *             jac[i-1, 0] += sum((-2*amp*((lx-mu)**2)*exp_term*(ly-amp_exp_term))/(sigma1**3))             # <<<<<<<<<<<<<<
 *             exp_term = np.exp(-((rx-mu)**2)/(2*sigma2**2))
 *             amp_exp_term = amp*exp_term
 */
      __pyx_t_5 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyNumber_Subtract(((PyObject *)__pyx_v_lx), __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Power(__pyx_t_4, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_v_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Subtract(((PyObject *)__pyx_v_ly), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyFloat_FromDouble(powf(__pyx_v_sigma1, 3.0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_24 = (__pyx_v_i - 1);
      __pyx_t_25 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_24 < 0) {
        __pyx_t_24 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_24 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_24 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_25 < 0) {
        __pyx_t_25 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_25 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 71, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":72
 *             jac[i-2, 0] += sum((-2*amp*(lx-mu)*exp_term*(ly-amp_exp_term))/(sigma1**2))
 *             jac[i-1, 0] += sum((-2*amp*((lx-mu)**2)*exp_term*(ly-amp_exp_term))/(sigma1**3))
 *             exp_term = np.exp(-((rx-mu)**2)/(2*sigma2**2))             # <<<<<<<<<<<<<<
 *             amp_exp_term = amp*exp_term
 *             prefix = 2*amp_exp_term
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_rx), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Negative(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma2, 2.0))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __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_3);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __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_DECREF_SET(__pyx_v_exp_term, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":73
 *             jac[i-1, 0] += sum((-2*amp*((lx-mu)**2)*exp_term*(ly-amp_exp_term))/(sigma1**3))
 *             exp_term = np.exp(-((rx-mu)**2)/(2*sigma2**2))
 *             amp_exp_term = amp*exp_term             # <<<<<<<<<<<<<<
 *             prefix = 2*amp_exp_term
 *             # There is NO right side contribution to the jacobian of the amplitude because rx is defined as
 */
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 73, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF_SET(__pyx_v_amp_exp_term, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyquant/cpeaks.pyx":74
 *             exp_term = np.exp(-((rx-mu)**2)/(2*sigma2**2))
 *             amp_exp_term = amp*exp_term
 *             prefix = 2*amp_exp_term             # <<<<<<<<<<<<<<
 *             # There is NO right side contribution to the jacobian of the amplitude because rx is defined as
 *             # x>mu, therefore anything by the right side of the bigaussian function does not change the amplitude
 */
      __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF_SET(__pyx_v_prefix, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyquant/cpeaks.pyx":77
 *             # There is NO right side contribution to the jacobian of the amplitude because rx is defined as
 *             # x>mu, therefore anything by the right side of the bigaussian function does not change the amplitude
 *             jac[i-3, 0] += sum(-2*exp_term*(ry-amp_exp_term))             # <<<<<<<<<<<<<<
 *             jac[i-2, 0] += sum((-2*amp*(rx-mu)*exp_term*(ry-amp_exp_term))/sigma2**2)
 *             jac[i, 0] += sum((-2*amp*((rx-mu)**2)*exp_term*(ry-amp_exp_term))/(sigma2**3))
 */
      __pyx_t_5 = PyNumber_Multiply(__pyx_int_neg_2, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_ry), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __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 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_26 = (__pyx_v_i - 3);
      __pyx_t_27 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_26 < 0) {
        __pyx_t_26 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_26 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_27 < 0) {
        __pyx_t_27 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_27 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 77, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":78
 *             # x>mu, therefore anything by the right side of the bigaussian function does not change the amplitude
 *             jac[i-3, 0] += sum(-2*exp_term*(ry-amp_exp_term))
 *             jac[i-2, 0] += sum((-2*amp*(rx-mu)*exp_term*(ry-amp_exp_term))/sigma2**2)             # <<<<<<<<<<<<<<
 *             jac[i, 0] += sum((-2*amp*((rx-mu)**2)*exp_term*(ry-amp_exp_term))/(sigma2**3))
 *     return jac.transpose()
 */
      __pyx_t_2 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Subtract(((PyObject *)__pyx_v_rx), __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __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_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_ry), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyFloat_FromDouble(powf(__pyx_v_sigma2, 2.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __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 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 78, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_28 = (__pyx_v_i - 2);
      __pyx_t_29 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_28 < 0) {
        __pyx_t_28 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_28 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 78, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":79
 *             jac[i-3, 0] += sum(-2*exp_term*(ry-amp_exp_term))
 *             jac[i-2, 0] += sum((-2*amp*(rx-mu)*exp_term*(ry-amp_exp_term))/sigma2**2)
 *             jac[i, 0] += sum((-2*amp*((rx-mu)**2)*exp_term*(ry-amp_exp_term))/(sigma2**3))             # <<<<<<<<<<<<<<
 *     return jac.transpose()
 * 
 */
      __pyx_t_5 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_rx), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_ry), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyFloat_FromDouble(powf(__pyx_v_sigma2, 3.0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_30 = __pyx_v_i;
      __pyx_t_31 = 0;
      __pyx_t_14 = -1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_pybuffernd_jac.diminfo[0].shape;
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_jac.diminfo[0].shape)) __pyx_t_14 = 0;
      if (__pyx_t_31 < 0) {
        __pyx_t_31 += __pyx_pybuffernd_jac.diminfo[1].shape;
        if (unlikely(__pyx_t_31 < 0)) __pyx_t_14 = 1;
      } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_jac.diminfo[1].shape)) __pyx_t_14 = 1;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 79, __pyx_L1_error)
      }
      *__Pyx_BufPtrStrided2d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_jac.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_jac.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_jac.diminfo[1].strides) += __pyx_t_19;

      /* "pyquant/cpeaks.pyx":57
 *         elif i%4 == 2:
 *             stdl = params[i]
 *         elif i%4 == 3:             # <<<<<<<<<<<<<<
 *             stdr = params[i]
 *             sigma1 = stdl/1.177
 */
    }
    __pyx_L5:;
  }

  /* "pyquant/cpeaks.pyx":80
 *             jac[i-2, 0] += sum((-2*amp*(rx-mu)*exp_term*(ry-amp_exp_term))/sigma2**2)
 *             jac[i, 0] += sum((-2*amp*((rx-mu)**2)*exp_term*(ry-amp_exp_term))/(sigma2**3))
 *     return jac.transpose()             # <<<<<<<<<<<<<<
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] gauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_jac), __pyx_n_s_transpose); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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, 80, __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, 80, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __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, 80, __pyx_L1_error)
  __pyx_r = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":44
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] bigauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=2] jac
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx, ly, rx, ry
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_jac.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lx.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ly.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rx.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ry.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_jac.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lx.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ly.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rx.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ry.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_jac);
  __Pyx_XDECREF((PyObject *)__pyx_v_lx);
  __Pyx_XDECREF((PyObject *)__pyx_v_ly);
  __Pyx_XDECREF((PyObject *)__pyx_v_rx);
  __Pyx_XDECREF((PyObject *)__pyx_v_ry);
  __Pyx_XDECREF(__pyx_v_exp_term);
  __Pyx_XDECREF(__pyx_v_amp_exp_term);
  __Pyx_XDECREF(__pyx_v_prefix);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_5bigauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_5bigauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_params = 0;
  PyArrayObject *__pyx_v_x = 0;
  PyArrayObject *__pyx_v_y = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bigauss_jac (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_params,&__pyx_n_s_x,&__pyx_n_s_y,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_x)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bigauss_jac", 1, 3, 3, 1); __PYX_ERR(0, 44, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bigauss_jac", 1, 3, 3, 2); __PYX_ERR(0, 44, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bigauss_jac") < 0)) __PYX_ERR(0, 44, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_params = ((PyArrayObject *)values[0]);
    __pyx_v_x = ((PyArrayObject *)values[1]);
    __pyx_v_y = ((PyArrayObject *)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bigauss_jac", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 44, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_params), __pyx_ptype_5numpy_ndarray, 1, "params", 0))) __PYX_ERR(0, 44, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5numpy_ndarray, 1, "x", 0))) __PYX_ERR(0, 44, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5numpy_ndarray, 1, "y", 0))) __PYX_ERR(0, 44, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_4bigauss_jac(__pyx_self, __pyx_v_params, __pyx_v_x, __pyx_v_y);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_4bigauss_jac(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("bigauss_jac", 0);
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 44, __pyx_L1_error)
  }
  __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_bigauss_jac(__pyx_v_params, __pyx_v_x, __pyx_v_y, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":82
 *     return jac.transpose()
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] gauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=2] jac
 *     cdef float amp, mu, sigma
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_7gauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_gauss_jac(PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_jac = 0;
  float __pyx_v_amp;
  float __pyx_v_mu;
  float __pyx_v_sigma;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_exp_term = NULL;
  PyObject *__pyx_v_amp_exp_term = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_jac;
  __Pyx_Buffer __pyx_pybuffer_jac;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  float __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  __Pyx_RefNannySetupContext("gauss_jac", 0);
  __pyx_pybuffer_jac.pybuffer.buf = NULL;
  __pyx_pybuffer_jac.refcount = 0;
  __pyx_pybuffernd_jac.data = NULL;
  __pyx_pybuffernd_jac.rcbuffer = &__pyx_pybuffer_jac;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":85
 *     cdef np.ndarray[FLOAT_t, ndim=2] jac
 *     cdef float amp, mu, sigma
 *     jac = np.zeros([len(params), 1])             # <<<<<<<<<<<<<<
 *     for i in xrange(len(params)):
 *         if i%3 == 0:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = PyObject_Length(((PyObject *)__pyx_v_params)); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 85, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_int_1);
  __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 85, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_jac.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_jac.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_jac.rcbuffer->pybuffer, (PyObject*)__pyx_v_jac, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 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_jac.diminfo[0].strides = __pyx_pybuffernd_jac.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_jac.diminfo[0].shape = __pyx_pybuffernd_jac.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_jac.diminfo[1].strides = __pyx_pybuffernd_jac.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_jac.diminfo[1].shape = __pyx_pybuffernd_jac.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 85, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_jac = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":86
 *     cdef float amp, mu, sigma
 *     jac = np.zeros([len(params), 1])
 *     for i in xrange(len(params)):             # <<<<<<<<<<<<<<
 *         if i%3 == 0:
 *             amp = params[i]
 */
  __pyx_t_4 = PyObject_Length(((PyObject *)__pyx_v_params)); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 86, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __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_xrange, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_12 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_12 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 86, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_12)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 86, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 86, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_12(__pyx_t_3);
      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, 86, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":87
 *     jac = np.zeros([len(params), 1])
 *     for i in xrange(len(params)):
 *         if i%3 == 0:             # <<<<<<<<<<<<<<
 *             amp = params[i]
 *         elif i%3 == 1:
 */
    __pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_13) {

      /* "pyquant/cpeaks.pyx":88
 *     for i in xrange(len(params)):
 *         if i%3 == 0:
 *             amp = params[i]             # <<<<<<<<<<<<<<
 *         elif i%3 == 1:
 *             mu = params[i]
 */
      __pyx_t_6 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_14 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_14 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_amp = __pyx_t_14;

      /* "pyquant/cpeaks.pyx":87
 *     jac = np.zeros([len(params), 1])
 *     for i in xrange(len(params)):
 *         if i%3 == 0:             # <<<<<<<<<<<<<<
 *             amp = params[i]
 *         elif i%3 == 1:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":89
 *         if i%3 == 0:
 *             amp = params[i]
 *         elif i%3 == 1:             # <<<<<<<<<<<<<<
 *             mu = params[i]
 *         elif i%3 == 2:
 */
    __pyx_t_6 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_13) {

      /* "pyquant/cpeaks.pyx":90
 *             amp = params[i]
 *         elif i%3 == 1:
 *             mu = params[i]             # <<<<<<<<<<<<<<
 *         elif i%3 == 2:
 *             sigma = params[i]
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_14 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_mu = __pyx_t_14;

      /* "pyquant/cpeaks.pyx":89
 *         if i%3 == 0:
 *             amp = params[i]
 *         elif i%3 == 1:             # <<<<<<<<<<<<<<
 *             mu = params[i]
 *         elif i%3 == 2:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":91
 *         elif i%3 == 1:
 *             mu = params[i]
 *         elif i%3 == 2:             # <<<<<<<<<<<<<<
 *             sigma = params[i]
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))
 */
    __pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 91, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_13) {

      /* "pyquant/cpeaks.pyx":92
 *             mu = params[i]
 *         elif i%3 == 2:
 *             sigma = params[i]             # <<<<<<<<<<<<<<
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))
 *             amp_exp_term = amp*exp_term
 */
      __pyx_t_6 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 92, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_14 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_14 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_sigma = __pyx_t_14;

      /* "pyquant/cpeaks.pyx":93
 *         elif i%3 == 2:
 *             sigma = params[i]
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))             # <<<<<<<<<<<<<<
 *             amp_exp_term = amp*exp_term
 *             jac[i-2, 0] += sum(-2*exp_term*(y-amp_exp_term))
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_x), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma, 2.0))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 93, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_GIVEREF(__pyx_t_15);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_15);
        __pyx_t_15 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 93, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF_SET(__pyx_v_exp_term, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "pyquant/cpeaks.pyx":94
 *             sigma = params[i]
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))
 *             amp_exp_term = amp*exp_term             # <<<<<<<<<<<<<<
 *             jac[i-2, 0] += sum(-2*exp_term*(y-amp_exp_term))
 *             jac[i-1, 0] += sum(-2*amp*(x-mu)*exp_term*(y-amp_exp_term)/(sigma**2))
 */
      __pyx_t_6 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_v_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 94, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_amp_exp_term, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pyquant/cpeaks.pyx":95
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))
 *             amp_exp_term = amp*exp_term
 *             jac[i-2, 0] += sum(-2*exp_term*(y-amp_exp_term))             # <<<<<<<<<<<<<<
 *             jac[i-1, 0] += sum(-2*amp*(x-mu)*exp_term*(y-amp_exp_term)/(sigma**2))
 *             jac[i, 0] += sum(-2*amp*((x-mu)**2)*exp_term*(y-amp_exp_term)/(sigma**3))
 */
      __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_v_i, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_0);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_GetItem(((PyObject *)__pyx_v_jac), __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyNumber_Multiply(__pyx_int_neg_2, __pyx_v_exp_term); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_15 = PyNumber_Subtract(((PyObject *)__pyx_v_y), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_jac), __pyx_t_6, __pyx_t_15) < 0)) __PYX_ERR(0, 95, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pyquant/cpeaks.pyx":96
 *             amp_exp_term = amp*exp_term
 *             jac[i-2, 0] += sum(-2*exp_term*(y-amp_exp_term))
 *             jac[i-1, 0] += sum(-2*amp*(x-mu)*exp_term*(y-amp_exp_term)/(sigma**2))             # <<<<<<<<<<<<<<
 *             jac[i, 0] += sum(-2*amp*((x-mu)**2)*exp_term*(y-amp_exp_term)/(sigma**3))
 *     # print(params, jac)
 */
      __pyx_t_6 = __Pyx_PyInt_SubtractObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_6);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_0);
      __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_GetItem(((PyObject *)__pyx_v_jac), __pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_x), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_5, __pyx_v_exp_term); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Subtract(((PyObject *)__pyx_v_y), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __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_5 = PyFloat_FromDouble(powf(__pyx_v_sigma, 2.0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_jac), __pyx_t_15, __pyx_t_5) < 0)) __PYX_ERR(0, 96, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":97
 *             jac[i-2, 0] += sum(-2*exp_term*(y-amp_exp_term))
 *             jac[i-1, 0] += sum(-2*amp*(x-mu)*exp_term*(y-amp_exp_term)/(sigma**2))
 *             jac[i, 0] += sum(-2*amp*((x-mu)**2)*exp_term*(y-amp_exp_term)/(sigma**3))             # <<<<<<<<<<<<<<
 *     # print(params, jac)
 *     return jac.transpose()
 */
      __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_INCREF(__pyx_v_i);
      __Pyx_GIVEREF(__pyx_v_i);
      PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_i);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_0);
      __pyx_t_5 = PyObject_GetItem(((PyObject *)__pyx_v_jac), __pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyFloat_FromDouble((-2.0 * __pyx_v_amp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_x), __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Multiply(__pyx_t_1, __pyx_v_exp_term); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Subtract(((PyObject *)__pyx_v_y), __pyx_v_amp_exp_term); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyFloat_FromDouble(powf(__pyx_v_sigma, 3.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_jac), __pyx_t_15, __pyx_t_1) < 0)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":91
 *         elif i%3 == 1:
 *             mu = params[i]
 *         elif i%3 == 2:             # <<<<<<<<<<<<<<
 *             sigma = params[i]
 *             exp_term = np.exp(-((x-mu)**2)/(2*sigma**2))
 */
    }
    __pyx_L5:;

    /* "pyquant/cpeaks.pyx":86
 *     cdef float amp, mu, sigma
 *     jac = np.zeros([len(params), 1])
 *     for i in xrange(len(params)):             # <<<<<<<<<<<<<<
 *         if i%3 == 0:
 *             amp = params[i]
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":99
 *             jac[i, 0] += sum(-2*amp*((x-mu)**2)*exp_term*(y-amp_exp_term)/(sigma**3))
 *     # print(params, jac)
 *     return jac.transpose()             # <<<<<<<<<<<<<<
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] bigauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float stdl, float stdr):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_jac), __pyx_n_s_transpose); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 99, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 99, __pyx_L1_error)
  __pyx_r = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":82
 *     return jac.transpose()
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=2] gauss_jac(np.ndarray[FLOAT_t, ndim=1] params, np.ndarray[FLOAT_t, ndim=1] x, np.ndarray[FLOAT_t, ndim=1] y):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=2] jac
 *     cdef float amp, mu, sigma
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_15);
  { 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_jac.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_jac.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_jac);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_exp_term);
  __Pyx_XDECREF(__pyx_v_amp_exp_term);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_7gauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_7gauss_jac(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_params = 0;
  PyArrayObject *__pyx_v_x = 0;
  PyArrayObject *__pyx_v_y = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gauss_jac (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_params,&__pyx_n_s_x,&__pyx_n_s_y,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_x)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gauss_jac", 1, 3, 3, 1); __PYX_ERR(0, 82, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gauss_jac", 1, 3, 3, 2); __PYX_ERR(0, 82, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gauss_jac") < 0)) __PYX_ERR(0, 82, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_params = ((PyArrayObject *)values[0]);
    __pyx_v_x = ((PyArrayObject *)values[1]);
    __pyx_v_y = ((PyArrayObject *)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("gauss_jac", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 82, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_params), __pyx_ptype_5numpy_ndarray, 1, "params", 0))) __PYX_ERR(0, 82, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5numpy_ndarray, 1, "x", 0))) __PYX_ERR(0, 82, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5numpy_ndarray, 1, "y", 0))) __PYX_ERR(0, 82, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_6gauss_jac(__pyx_self, __pyx_v_params, __pyx_v_x, __pyx_v_y);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_6gauss_jac(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_params, PyArrayObject *__pyx_v_x, PyArrayObject *__pyx_v_y) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("gauss_jac", 0);
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 82, __pyx_L1_error)
  }
  __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_gauss_jac(__pyx_v_params, __pyx_v_x, __pyx_v_y, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.gauss_jac", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":101
 *     return jac.transpose()
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] bigauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float stdl, float stdr):             # <<<<<<<<<<<<<<
 *     cdef float sigma1 = stdl/1.177
 *     cdef float sigma2 = stdr/1.177
 */

static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss(PyArrayObject *__pyx_v_x, float __pyx_v_amp, float __pyx_v_mu, float __pyx_v_stdl, float __pyx_v_stdr) {
  float __pyx_v_sigma1;
  float __pyx_v_sigma2;
  PyArrayObject *__pyx_v_lx = 0;
  PyArrayObject *__pyx_v_left = 0;
  PyArrayObject *__pyx_v_rx = 0;
  PyArrayObject *__pyx_v_right = 0;
  PyArrayObject *__pyx_v_y = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_left;
  __Pyx_Buffer __pyx_pybuffer_left;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lx;
  __Pyx_Buffer __pyx_pybuffer_lx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_right;
  __Pyx_Buffer __pyx_pybuffer_right;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rx;
  __Pyx_Buffer __pyx_pybuffer_rx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_x;
  __Pyx_Buffer __pyx_pybuffer_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyArrayObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyArrayObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  __Pyx_RefNannySetupContext("bigauss", 0);
  __pyx_pybuffer_lx.pybuffer.buf = NULL;
  __pyx_pybuffer_lx.refcount = 0;
  __pyx_pybuffernd_lx.data = NULL;
  __pyx_pybuffernd_lx.rcbuffer = &__pyx_pybuffer_lx;
  __pyx_pybuffer_left.pybuffer.buf = NULL;
  __pyx_pybuffer_left.refcount = 0;
  __pyx_pybuffernd_left.data = NULL;
  __pyx_pybuffernd_left.rcbuffer = &__pyx_pybuffer_left;
  __pyx_pybuffer_rx.pybuffer.buf = NULL;
  __pyx_pybuffer_rx.refcount = 0;
  __pyx_pybuffernd_rx.data = NULL;
  __pyx_pybuffernd_rx.rcbuffer = &__pyx_pybuffer_rx;
  __pyx_pybuffer_right.pybuffer.buf = NULL;
  __pyx_pybuffer_right.refcount = 0;
  __pyx_pybuffernd_right.data = NULL;
  __pyx_pybuffernd_right.rcbuffer = &__pyx_pybuffer_right;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  __pyx_pybuffer_x.pybuffer.buf = NULL;
  __pyx_pybuffer_x.refcount = 0;
  __pyx_pybuffernd_x.data = NULL;
  __pyx_pybuffernd_x.rcbuffer = &__pyx_pybuffer_x;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 101, __pyx_L1_error)
  }
  __pyx_pybuffernd_x.diminfo[0].strides = __pyx_pybuffernd_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x.diminfo[0].shape = __pyx_pybuffernd_x.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":102
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] bigauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float stdl, float stdr):
 *     cdef float sigma1 = stdl/1.177             # <<<<<<<<<<<<<<
 *     cdef float sigma2 = stdr/1.177
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx = x[x<=mu]
 */
  __pyx_v_sigma1 = (__pyx_v_stdl / 1.177);

  /* "pyquant/cpeaks.pyx":103
 * cdef np.ndarray[FLOAT_t, ndim=1] bigauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float stdl, float stdr):
 *     cdef float sigma1 = stdl/1.177
 *     cdef float sigma2 = stdr/1.177             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx = x[x<=mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] left = amp*np.exp(-(lx-mu)**2/(2*sigma1**2))
 */
  __pyx_v_sigma2 = (__pyx_v_stdr / 1.177);

  /* "pyquant/cpeaks.pyx":104
 *     cdef float sigma1 = stdl/1.177
 *     cdef float sigma2 = stdr/1.177
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx = x[x<=mu]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] left = amp*np.exp(-(lx-mu)**2/(2*sigma1**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] rx = x[x>mu]
 */
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_1, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_x), __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __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, 104, __pyx_L1_error)
  __pyx_t_3 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lx.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_lx = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lx.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 104, __pyx_L1_error)
    } else {__pyx_pybuffernd_lx.diminfo[0].strides = __pyx_pybuffernd_lx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lx.diminfo[0].shape = __pyx_pybuffernd_lx.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_3 = 0;
  __pyx_v_lx = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":105
 *     cdef float sigma2 = stdr/1.177
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx = x[x<=mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] left = amp*np.exp(-(lx-mu)**2/(2*sigma1**2))             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] rx = x[x>mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] right = amp*np.exp(-(rx-mu)**2/(2*sigma2**2))
 */
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __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, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyNumber_Subtract(((PyObject *)__pyx_v_lx), __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Power(__pyx_t_6, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Negative(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma1, 2.0))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 105, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_left.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_left = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_left.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 105, __pyx_L1_error)
    } else {__pyx_pybuffernd_left.diminfo[0].strides = __pyx_pybuffernd_left.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_left.diminfo[0].shape = __pyx_pybuffernd_left.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_left = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":106
 *     cdef np.ndarray[FLOAT_t, ndim=1] lx = x[x<=mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] left = amp*np.exp(-(lx-mu)**2/(2*sigma1**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] rx = x[x>mu]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] right = amp*np.exp(-(rx-mu)**2/(2*sigma2**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = np.concatenate([left, right], axis=0)
 */
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_x), __pyx_t_5, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_GetItem(((PyObject *)__pyx_v_x), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __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, 106, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rx.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_rx = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_rx.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 106, __pyx_L1_error)
    } else {__pyx_pybuffernd_rx.diminfo[0].strides = __pyx_pybuffernd_rx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rx.diminfo[0].shape = __pyx_pybuffernd_rx.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_rx = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":107
 *     cdef np.ndarray[FLOAT_t, ndim=1] left = amp*np.exp(-(lx-mu)**2/(2*sigma1**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] rx = x[x>mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] right = amp*np.exp(-(rx-mu)**2/(2*sigma2**2))             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = np.concatenate([left, right], axis=0)
 *     return y
 */
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_amp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_exp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyNumber_Subtract(((PyObject *)__pyx_v_rx), __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Power(__pyx_t_7, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma2, 2.0))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 107, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_right.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_right = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_right.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 107, __pyx_L1_error)
    } else {__pyx_pybuffernd_right.diminfo[0].strides = __pyx_pybuffernd_right.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_right.diminfo[0].shape = __pyx_pybuffernd_right.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_right = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":108
 *     cdef np.ndarray[FLOAT_t, ndim=1] rx = x[x>mu]
 *     cdef np.ndarray[FLOAT_t, ndim=1] right = amp*np.exp(-(rx-mu)**2/(2*sigma2**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = np.concatenate([left, right], axis=0)             # <<<<<<<<<<<<<<
 *     return y
 * 
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_concatenate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(((PyObject *)__pyx_v_left));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_left));
  PyList_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_left));
  __Pyx_INCREF(((PyObject *)__pyx_v_right));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_right));
  PyList_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_right));
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_axis, __pyx_int_0) < 0) __PYX_ERR(0, 108, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 108, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_y = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_y.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 108, __pyx_L1_error)
    } else {__pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_11 = 0;
  __pyx_v_y = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "pyquant/cpeaks.pyx":109
 *     cdef np.ndarray[FLOAT_t, ndim=1] right = amp*np.exp(-(rx-mu)**2/(2*sigma2**2))
 *     cdef np.ndarray[FLOAT_t, ndim=1] y = np.concatenate([left, right], axis=0)
 *     return y             # <<<<<<<<<<<<<<
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] bigauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_y));
  __pyx_r = ((PyArrayObject *)__pyx_v_y);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":101
 *     return jac.transpose()
 * 
 * cdef np.ndarray[FLOAT_t, ndim=1] bigauss(np.ndarray[FLOAT_t, ndim=1] x, float amp, float mu, float stdl, float stdr):             # <<<<<<<<<<<<<<
 *     cdef float sigma1 = stdl/1.177
 *     cdef float sigma2 = stdr/1.177
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_7);
  { 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_left.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lx.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_right.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rx.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_left.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lx.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_right.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rx.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_lx);
  __Pyx_XDECREF((PyObject *)__pyx_v_left);
  __Pyx_XDECREF((PyObject *)__pyx_v_rx);
  __Pyx_XDECREF((PyObject *)__pyx_v_right);
  __Pyx_XDECREF((PyObject *)__pyx_v_y);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":111
 *     return y
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] bigauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] amps
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_9bigauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_bigauss_ndim(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_amps = 0;
  PyArrayObject *__pyx_v_mus = 0;
  PyArrayObject *__pyx_v_sigmasl = 0;
  PyArrayObject *__pyx_v_sigmasr = 0;
  PyArrayObject *__pyx_v_data = 0;
  PyObject *__pyx_v_amp = NULL;
  PyObject *__pyx_v_mu = NULL;
  PyObject *__pyx_v_sigma1 = NULL;
  PyObject *__pyx_v_sigma2 = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_amps;
  __Pyx_Buffer __pyx_pybuffer_amps;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
  __Pyx_Buffer __pyx_pybuffer_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_mus;
  __Pyx_Buffer __pyx_pybuffer_mus;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_sigmasl;
  __Pyx_Buffer __pyx_pybuffer_sigmasl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_sigmasr;
  __Pyx_Buffer __pyx_pybuffer_sigmasr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  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;
  PyArrayObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  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;
  PyArrayObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  PyArrayObject *__pyx_t_15 = NULL;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *(*__pyx_t_19)(PyObject *);
  float __pyx_t_20;
  float __pyx_t_21;
  float __pyx_t_22;
  float __pyx_t_23;
  __Pyx_RefNannySetupContext("bigauss_ndim", 0);
  __pyx_pybuffer_amps.pybuffer.buf = NULL;
  __pyx_pybuffer_amps.refcount = 0;
  __pyx_pybuffernd_amps.data = NULL;
  __pyx_pybuffernd_amps.rcbuffer = &__pyx_pybuffer_amps;
  __pyx_pybuffer_mus.pybuffer.buf = NULL;
  __pyx_pybuffer_mus.refcount = 0;
  __pyx_pybuffernd_mus.data = NULL;
  __pyx_pybuffernd_mus.rcbuffer = &__pyx_pybuffer_mus;
  __pyx_pybuffer_sigmasl.pybuffer.buf = NULL;
  __pyx_pybuffer_sigmasl.refcount = 0;
  __pyx_pybuffernd_sigmasl.data = NULL;
  __pyx_pybuffernd_sigmasl.rcbuffer = &__pyx_pybuffer_sigmasl;
  __pyx_pybuffer_sigmasr.pybuffer.buf = NULL;
  __pyx_pybuffer_sigmasr.refcount = 0;
  __pyx_pybuffernd_sigmasr.data = NULL;
  __pyx_pybuffernd_sigmasr.rcbuffer = &__pyx_pybuffer_sigmasr;
  __pyx_pybuffer_data.pybuffer.buf = NULL;
  __pyx_pybuffer_data.refcount = 0;
  __pyx_pybuffernd_data.data = NULL;
  __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 111, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 111, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":116
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmasl
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmasr
 *     amps, mus, sigmasl, sigmasr = params[::4], params[1::4], params[2::4], params[3::4]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):
 */
  __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __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, 116, __pyx_L1_error)
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __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, 116, __pyx_L1_error)
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 116, __pyx_L1_error)
  __pyx_t_4 = PyObject_GetItem(((PyObject *)__pyx_v_params), __pyx_slice__7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 116, __pyx_L1_error)
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_amps.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_amps.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_amps.rcbuffer->pybuffer, (PyObject*)__pyx_v_amps, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_amps.diminfo[0].strides = __pyx_pybuffernd_amps.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_amps.diminfo[0].shape = __pyx_pybuffernd_amps.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
  }
  __pyx_t_5 = 0;
  __pyx_v_amps = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mus.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_mus.rcbuffer->pybuffer, (PyObject*)__pyx_v_mus, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
      }
    }
    __pyx_pybuffernd_mus.diminfo[0].strides = __pyx_pybuffernd_mus.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_mus.diminfo[0].shape = __pyx_pybuffernd_mus.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
  }
  __pyx_t_10 = 0;
  __pyx_v_mus = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasl.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmasl.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmasl.rcbuffer->pybuffer, (PyObject*)__pyx_v_sigmasl, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_sigmasl.diminfo[0].strides = __pyx_pybuffernd_sigmasl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_sigmasl.diminfo[0].shape = __pyx_pybuffernd_sigmasl.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_sigmasl = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasr.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmasr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sigmasr.rcbuffer->pybuffer, (PyObject*)__pyx_v_sigmasr, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
      }
    }
    __pyx_pybuffernd_sigmasr.diminfo[0].strides = __pyx_pybuffernd_sigmasr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_sigmasr.diminfo[0].shape = __pyx_pybuffernd_sigmasr.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
  }
  __pyx_t_12 = 0;
  __pyx_v_sigmasr = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":117
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmasr
 *     amps, mus, sigmasl, sigmasr = params[::4], params[1::4], params[2::4], params[3::4]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))             # <<<<<<<<<<<<<<
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):
 *         data += bigauss(xdata, amp, mu, sigma1, sigma2)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_13 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 117, __pyx_L1_error)
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL;
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 117, __pyx_L1_error)
  __pyx_t_15 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 117, __pyx_L1_error)
    } else {__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_15 = 0;
  __pyx_v_data = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":118
 *     amps, mus, sigmasl, sigmasr = params[::4], params[1::4], params[2::4], params[3::4]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):             # <<<<<<<<<<<<<<
 *         data += bigauss(xdata, amp, mu, sigma1, sigma2)
 *     return data
 */
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_amps));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_amps));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_amps));
  __Pyx_INCREF(((PyObject *)__pyx_v_mus));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_mus));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_mus));
  __Pyx_INCREF(((PyObject *)__pyx_v_sigmasl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_sigmasl));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_sigmasl));
  __Pyx_INCREF(((PyObject *)__pyx_v_sigmasr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_sigmasr));
  PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_sigmasr));
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_4 = __pyx_t_2; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
    __pyx_t_16 = NULL;
  } else {
    __pyx_t_13 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 118, __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, 118, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  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_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 118, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 118, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_16(__pyx_t_4);
      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, 118, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 118, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_17 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_14 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_17 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_14);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_17);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_14,&__pyx_t_3,&__pyx_t_1,&__pyx_t_17};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 118, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_14,&__pyx_t_3,&__pyx_t_1,&__pyx_t_17};
      __pyx_t_18 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_19 = Py_TYPE(__pyx_t_18)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_19(__pyx_t_18); if (unlikely(!item)) goto __pyx_L5_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_19(__pyx_t_18), 4) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
      __pyx_t_19 = NULL;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __pyx_t_19 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 118, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_amp, __pyx_t_14);
    __pyx_t_14 = 0;
    __Pyx_XDECREF_SET(__pyx_v_mu, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_sigma1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_sigma2, __pyx_t_17);
    __pyx_t_17 = 0;

    /* "pyquant/cpeaks.pyx":119
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):
 *         data += bigauss(xdata, amp, mu, sigma1, sigma2)             # <<<<<<<<<<<<<<
 *     return data
 * 
 */
    __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_v_amp); if (unlikely((__pyx_t_20 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_21 = __pyx_PyFloat_AsFloat(__pyx_v_mu); if (unlikely((__pyx_t_21 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_22 = __pyx_PyFloat_AsFloat(__pyx_v_sigma1); if (unlikely((__pyx_t_22 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_23 = __pyx_PyFloat_AsFloat(__pyx_v_sigma2); if (unlikely((__pyx_t_23 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_2 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_bigauss(((PyArrayObject *)__pyx_v_xdata), __pyx_t_20, __pyx_t_21, __pyx_t_22, __pyx_t_23)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_17 = PyNumber_InPlaceAdd(((PyObject *)__pyx_v_data), __pyx_t_2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_17) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_17, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 119, __pyx_L1_error)
    __pyx_t_15 = ((PyArrayObject *)__pyx_t_17);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 119, __pyx_L1_error)
    }
    __pyx_t_15 = 0;
    __Pyx_DECREF_SET(__pyx_v_data, ((PyArrayObject *)__pyx_t_17));
    __pyx_t_17 = 0;

    /* "pyquant/cpeaks.pyx":118
 *     amps, mus, sigmasl, sigmasr = params[::4], params[1::4], params[2::4], params[3::4]
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):             # <<<<<<<<<<<<<<
 *         data += bigauss(xdata, amp, mu, sigma1, sigma2)
 *     return data
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":120
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):
 *         data += bigauss(xdata, amp, mu, sigma1, sigma2)
 *     return data             # <<<<<<<<<<<<<<
 * 
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_data));
  __pyx_r = ((PyArrayObject *)__pyx_v_data);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":111
 *     return y
 * 
 * cpdef np.ndarray[FLOAT_t, ndim=1] bigauss_ndim(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] params):             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] amps
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 */

  /* 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_14);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  { 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_amps.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_amps.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_mus.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sigmasr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_amps);
  __Pyx_XDECREF((PyObject *)__pyx_v_mus);
  __Pyx_XDECREF((PyObject *)__pyx_v_sigmasl);
  __Pyx_XDECREF((PyObject *)__pyx_v_sigmasr);
  __Pyx_XDECREF((PyObject *)__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_amp);
  __Pyx_XDECREF(__pyx_v_mu);
  __Pyx_XDECREF(__pyx_v_sigma1);
  __Pyx_XDECREF(__pyx_v_sigma2);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_9bigauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_9bigauss_ndim(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_params = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bigauss_ndim (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_params,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_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_params)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bigauss_ndim", 1, 2, 2, 1); __PYX_ERR(0, 111, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bigauss_ndim") < 0)) __PYX_ERR(0, 111, __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_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_params = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bigauss_ndim", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 111, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 111, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_params), __pyx_ptype_5numpy_ndarray, 1, "params", 0))) __PYX_ERR(0, 111, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_8bigauss_ndim(__pyx_self, __pyx_v_xdata, __pyx_v_params);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_8bigauss_ndim(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_params) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_params;
  __Pyx_Buffer __pyx_pybuffer_params;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("bigauss_ndim", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_params.pybuffer.buf = NULL;
  __pyx_pybuffer_params.refcount = 0;
  __pyx_pybuffernd_params.data = NULL;
  __pyx_pybuffernd_params.rcbuffer = &__pyx_pybuffer_params;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 111, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_params.rcbuffer->pybuffer, (PyObject*)__pyx_v_params, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 111, __pyx_L1_error)
  }
  __pyx_pybuffernd_params.diminfo[0].strides = __pyx_pybuffernd_params.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_params.diminfo[0].shape = __pyx_pybuffernd_params.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_bigauss_ndim(__pyx_v_xdata, __pyx_v_params, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_params.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_ndim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_params.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":122
 *     return data
 * 
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):             # <<<<<<<<<<<<<<
 *     if any([np.isnan(i) for i in guess]):
 *         return np.inf
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_11bigauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_bigauss_func(PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyArrayObject *__pyx_v_data = 0;
  float __pyx_v_residual;
  PyObject *__pyx_v_i = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
  __Pyx_Buffer __pyx_pybuffer_data;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  float __pyx_t_10;
  __Pyx_RefNannySetupContext("bigauss_func", 0);
  __pyx_pybuffer_data.pybuffer.buf = NULL;
  __pyx_pybuffer_data.refcount = 0;
  __pyx_pybuffernd_data.data = NULL;
  __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_v_guess, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":123
 * 
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 *     if any([np.isnan(i) for i in guess]):             # <<<<<<<<<<<<<<
 *         return np.inf
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = bigauss_ndim(xdata, guess)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(((PyObject *)__pyx_v_guess))) || PyTuple_CheckExact(((PyObject *)__pyx_v_guess))) {
    __pyx_t_2 = ((PyObject *)__pyx_v_guess); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_guess)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 123, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 123, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 123, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_2);
      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, 123, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_isnan); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 123, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_i);
      __Pyx_GIVEREF(__pyx_v_i);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_i);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 123, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_any, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_9) {

    /* "pyquant/cpeaks.pyx":124
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 *     if any([np.isnan(i) for i in guess]):
 *         return np.inf             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = bigauss_ndim(xdata, guess)
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_inf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_10 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_10 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_10;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":123
 * 
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):
 *     if any([np.isnan(i) for i in guess]):             # <<<<<<<<<<<<<<
 *         return np.inf
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = bigauss_ndim(xdata, guess)
 */
  }

  /* "pyquant/cpeaks.pyx":125
 *     if any([np.isnan(i) for i in guess]):
 *         return np.inf
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = bigauss_ndim(xdata, guess)             # <<<<<<<<<<<<<<
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 *     # residual sum of squares for this data.
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_bigauss_ndim(((PyArrayObject *)__pyx_v_xdata), ((PyArrayObject *)__pyx_v_guess), 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_data.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 125, __pyx_L1_error)
    } else {__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_data = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":128
 *     # absolute deviation as our distance metric. Empirically found to give better results than
 *     # residual sum of squares for this data.
 *     cdef float residual = sum((ydata-data)**2)             # <<<<<<<<<<<<<<
 *     # cdef float fit, real, res
 *     # cdef float residual = 0
 */
  __pyx_t_2 = PyNumber_Subtract(((PyObject *)__pyx_v_ydata), ((PyObject *)__pyx_v_data)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_10 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_10 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_residual = __pyx_t_10;

  /* "pyquant/cpeaks.pyx":138
 *     #         res = res*2*real/fit
 *     #     residual += res
 *     return residual             # <<<<<<<<<<<<<<
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 */
  __pyx_r = __pyx_v_residual;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":122
 *     return data
 * 
 * cpdef float bigauss_func(np.ndarray[FLOAT_t, ndim=1] guess, np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata):             # <<<<<<<<<<<<<<
 *     if any([np.isnan(i) for i in guess]):
 *         return np.inf
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __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_data.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_WriteUnraisable("pyquant.cpeaks.bigauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_11bigauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_11bigauss_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_guess = 0;
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bigauss_func (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_guess,&__pyx_n_s_xdata,&__pyx_n_s_ydata,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_guess)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xdata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bigauss_func", 1, 3, 3, 1); __PYX_ERR(0, 122, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bigauss_func", 1, 3, 3, 2); __PYX_ERR(0, 122, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bigauss_func") < 0)) __PYX_ERR(0, 122, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_guess = ((PyArrayObject *)values[0]);
    __pyx_v_xdata = ((PyArrayObject *)values[1]);
    __pyx_v_ydata = ((PyArrayObject *)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bigauss_func", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 122, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_guess), __pyx_ptype_5numpy_ndarray, 1, "guess", 0))) __PYX_ERR(0, 122, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 122, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 122, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_10bigauss_func(__pyx_self, __pyx_v_guess, __pyx_v_xdata, __pyx_v_ydata);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_10bigauss_func(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_guess, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("bigauss_func", 0);
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_v_guess, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 122, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_bigauss_func(__pyx_v_guess, __pyx_v_xdata, __pyx_v_ydata, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.bigauss_func", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":140
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_13fixedMeanFit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyArrayObject *__pyx_f_7pyquant_6cpeaks_fixedMeanFit(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit *__pyx_optional_args) {
  int __pyx_v_peak_index = ((int)1);
  float __pyx_v_rel_peak;
  float __pyx_v_peak_loc;
  int __pyx_v_peak_left;
  int __pyx_v_peak_right;
  float __pyx_v_peak_min;
  float __pyx_v_peak_max;
  float __pyx_v_average;
  float __pyx_v_variance;
  PyArrayObject *__pyx_v_bnds = 0;
  PyObject *__pyx_v_min_spacing = NULL;
  PyObject *__pyx_v_lb = NULL;
  PyObject *__pyx_v_rb = NULL;
  PyArrayObject *__pyx_v_guess = 0;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_base_opts = NULL;
  PyObject *__pyx_v_routines = NULL;
  PyObject *__pyx_v_routine = NULL;
  PyObject *__pyx_v_opts = NULL;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_v_traceback = NULL;
  float __pyx_v_lowest;
  PyArrayObject *__pyx_v_best = 0;
  PyObject *__pyx_v_i = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_best;
  __Pyx_Buffer __pyx_pybuffer_best;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bnds;
  __Pyx_Buffer __pyx_pybuffer_bnds;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  __pyx_t_7pyquant_6cpeaks_FLOAT_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  __pyx_t_7pyquant_6cpeaks_FLOAT_t __pyx_t_16;
  int __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  Py_ssize_t __pyx_t_19;
  PyObject *__pyx_t_20 = NULL;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  PyObject *__pyx_t_24 = NULL;
  PyObject *__pyx_t_25 = NULL;
  PyArrayObject *__pyx_t_26 = NULL;
  float __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  int __pyx_t_32;
  Py_ssize_t __pyx_t_33;
  Py_ssize_t __pyx_t_34;
  PyArrayObject *__pyx_t_35 = NULL;
  PyObject *(*__pyx_t_36)(PyObject *);
  int __pyx_t_37;
  PyArrayObject *__pyx_t_38 = NULL;
  __Pyx_RefNannySetupContext("fixedMeanFit", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_peak_index = __pyx_optional_args->peak_index;
    }
  }
  __Pyx_INCREF((PyObject *)__pyx_v_xdata);
  __Pyx_INCREF((PyObject *)__pyx_v_ydata);
  __pyx_pybuffer_bnds.pybuffer.buf = NULL;
  __pyx_pybuffer_bnds.refcount = 0;
  __pyx_pybuffernd_bnds.data = NULL;
  __pyx_pybuffernd_bnds.rcbuffer = &__pyx_pybuffer_bnds;
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_best.pybuffer.buf = NULL;
  __pyx_pybuffer_best.refcount = 0;
  __pyx_pybuffernd_best.data = NULL;
  __pyx_pybuffernd_best.rcbuffer = &__pyx_pybuffer_best;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 140, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 140, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":142
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]             # <<<<<<<<<<<<<<
 *     cdef float peak_loc = xdata[peak_index]
 *     cdef int peak_left, peak_right
 */
  __pyx_t_1 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_pybuffernd_ydata.diminfo[0].shape;
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_pybuffernd_ydata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 142, __pyx_L1_error)
  }
  __pyx_v_rel_peak = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_ydata.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_ydata.diminfo[0].strides));

  /* "pyquant/cpeaks.pyx":143
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]
 *     cdef float peak_loc = xdata[peak_index]             # <<<<<<<<<<<<<<
 *     cdef int peak_left, peak_right
 *     cdef float peak_min, peak_max, average, variance
 */
  __pyx_t_3 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_3 < 0) {
    __pyx_t_3 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_3 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_3 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 143, __pyx_L1_error)
  }
  __pyx_v_peak_loc = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_3, __pyx_pybuffernd_xdata.diminfo[0].strides));

  /* "pyquant/cpeaks.pyx":148
 *     cdef np.ndarray[FLOAT_t, ndim=1] bnds
 * 
 *     ydata /= ydata.max()             # <<<<<<<<<<<<<<
 *     peak_left, peak_right = findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)
 *     peak_min, peak_max = xdata[0], xdata[-1]
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_max); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_6) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_ydata), __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 148, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 148, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_ydata, ((PyArrayObject *)__pyx_t_5));
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":149
 * 
 *     ydata /= ydata.max()
 *     peak_left, peak_right = findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)             # <<<<<<<<<<<<<<
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_convolve); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_kaiser); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_mode, __pyx_n_s_same) < 0) __PYX_ERR(0, 149, __pyx_L1_error)
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 149, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7pyquant_6cpeaks_findPeak(((PyArrayObject *)__pyx_t_11), __pyx_v_peak_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (likely(__pyx_t_6 != Py_None)) {
    PyObject* sequence = __pyx_t_6;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 149, __pyx_L1_error)
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 149, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_peak_left = __pyx_t_2;
  __pyx_v_peak_right = __pyx_t_12;

  /* "pyquant/cpeaks.pyx":150
 *     ydata /= ydata.max()
 *     peak_left, peak_right = findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)
 *     peak_min, peak_max = xdata[0], xdata[-1]             # <<<<<<<<<<<<<<
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:
 */
  __pyx_t_13 = 0;
  __pyx_t_12 = -1;
  if (__pyx_t_13 < 0) {
    __pyx_t_13 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_13 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 150, __pyx_L1_error)
  }
  __pyx_t_14 = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_xdata.diminfo[0].strides));
  __pyx_t_15 = -1L;
  __pyx_t_12 = -1;
  if (__pyx_t_15 < 0) {
    __pyx_t_15 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_15 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 150, __pyx_L1_error)
  }
  __pyx_t_16 = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_xdata.diminfo[0].strides));
  __pyx_v_peak_min = __pyx_t_14;
  __pyx_v_peak_max = __pyx_t_16;

  /* "pyquant/cpeaks.pyx":152
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:             # <<<<<<<<<<<<<<
 *         peak_index -= peak_left-1
 *     else:
 */
  __pyx_t_17 = ((__pyx_v_peak_index == __pyx_v_peak_right) != 0);
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":153
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:
 *         peak_index -= peak_left-1             # <<<<<<<<<<<<<<
 *     else:
 *         peak_index -= peak_left
 */
    __pyx_v_peak_index = (__pyx_v_peak_index - (__pyx_v_peak_left - 1));

    /* "pyquant/cpeaks.pyx":152
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:             # <<<<<<<<<<<<<<
 *         peak_index -= peak_left-1
 *     else:
 */
    goto __pyx_L3;
  }

  /* "pyquant/cpeaks.pyx":155
 *         peak_index -= peak_left-1
 *     else:
 *         peak_index -= peak_left             # <<<<<<<<<<<<<<
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 */
  /*else*/ {
    __pyx_v_peak_index = (__pyx_v_peak_index - __pyx_v_peak_left);
  }
  __pyx_L3:;

  /* "pyquant/cpeaks.pyx":156
 *     else:
 *         peak_index -= peak_left
 *     xdata = xdata[peak_left:peak_right]             # <<<<<<<<<<<<<<
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:
 */
  __pyx_t_6 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 156, __pyx_L1_error)
  __pyx_t_18 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
  }
  __pyx_t_18 = 0;
  __Pyx_DECREF_SET(__pyx_v_xdata, ((PyArrayObject *)__pyx_t_6));
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":157
 *         peak_index -= peak_left
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]             # <<<<<<<<<<<<<<
 *     if ydata.sum() == 0:
 *         return None
 */
  __pyx_t_6 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 157, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_ydata, ((PyArrayObject *)__pyx_t_6));
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":158
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:             # <<<<<<<<<<<<<<
 *         return None
 *     min_spacing = min(np.diff(xdata))/2
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_sum); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (__pyx_t_11) {
    __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  } else {
    __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 158, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":159
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:
 *         return None             # <<<<<<<<<<<<<<
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyArrayObject *)Py_None);
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":158
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:             # <<<<<<<<<<<<<<
 *         return None
 *     min_spacing = min(np.diff(xdata))/2
 */
  }

  /* "pyquant/cpeaks.pyx":160
 *     if ydata.sum() == 0:
 *         return None
 *     min_spacing = min(np.diff(xdata))/2             # <<<<<<<<<<<<<<
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_diff); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_11, ((PyObject *)__pyx_v_xdata)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
    __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_xdata));
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_int_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_min_spacing = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":161
 *         return None
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])             # <<<<<<<<<<<<<<
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_fabs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_19 = 0;
  __pyx_t_12 = -1;
  if (__pyx_t_19 < 0) {
    __pyx_t_19 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_19 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 161, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((__pyx_v_peak_loc - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_xdata.diminfo[0].strides)))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_11);
  } else {
    __pyx_t_20 = PyTuple_New(1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 161, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_6); __pyx_t_6 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_20, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_20, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_lb = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":162
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)             # <<<<<<<<<<<<<<
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_fabs); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_21 = -1L;
  __pyx_t_12 = -1;
  if (__pyx_t_21 < 0) {
    __pyx_t_21 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_21 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 162, __pyx_L1_error)
  }
  __pyx_t_5 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_loc)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_20))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_20);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_20, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_5); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_11);
  } else {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  __pyx_v_rb = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":163
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:             # <<<<<<<<<<<<<<
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 */
  __pyx_t_11 = PyObject_RichCompare(__pyx_v_lb, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 163, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":164
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:
 *         lb = min_spacing*5             # <<<<<<<<<<<<<<
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 */
    __pyx_t_11 = PyNumber_Multiply(__pyx_v_min_spacing, __pyx_int_5); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF_SET(__pyx_v_lb, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "pyquant/cpeaks.pyx":163
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:             # <<<<<<<<<<<<<<
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 */
  }

  /* "pyquant/cpeaks.pyx":165
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 *     if rb < min_spacing:             # <<<<<<<<<<<<<<
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 */
  __pyx_t_11 = PyObject_RichCompare(__pyx_v_rb, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 165, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":166
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 *         rb = min_spacing*5             # <<<<<<<<<<<<<<
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 *     #print bnds, xdata, peak_loc
 */
    __pyx_t_11 = PyNumber_Multiply(__pyx_v_min_spacing, __pyx_int_5); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF_SET(__pyx_v_rb, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "pyquant/cpeaks.pyx":165
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 *     if rb < min_spacing:             # <<<<<<<<<<<<<<
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 */
  }

  /* "pyquant/cpeaks.pyx":167
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])             # <<<<<<<<<<<<<<
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 */
  __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  if (((__pyx_v_rel_peak > 0.0) != 0)) {
    __pyx_t_5 = PyFloat_FromDouble((__pyx_v_rel_peak * 0.75)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __Pyx_INCREF(__pyx_float_1_01);
    __Pyx_GIVEREF(__pyx_float_1_01);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_float_1_01);
    __pyx_t_5 = 0;
    __pyx_t_20 = __pyx_t_4;
    __pyx_t_4 = 0;
  } else {
    __Pyx_INCREF(__pyx_tuple__9);
    __pyx_t_20 = __pyx_tuple__9;
  }
  __pyx_t_22 = 0;
  __pyx_t_12 = -1;
  if (__pyx_t_22 < 0) {
    __pyx_t_22 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_22 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 167, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_23 = -1L;
  __pyx_t_12 = -1;
  if (__pyx_t_23 < 0) {
    __pyx_t_23 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_23 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 167, __pyx_L1_error)
  }
  __pyx_t_5 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_24 = PyTuple_New(2); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_24);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_min_spacing);
  __Pyx_GIVEREF(__pyx_v_min_spacing);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_min_spacing);
  __Pyx_INCREF(__pyx_v_lb);
  __Pyx_GIVEREF(__pyx_v_lb);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_lb);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_min_spacing);
  __Pyx_GIVEREF(__pyx_v_min_spacing);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_min_spacing);
  __Pyx_INCREF(__pyx_v_rb);
  __Pyx_GIVEREF(__pyx_v_rb);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_rb);
  __pyx_t_25 = PyList_New(4); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  __Pyx_GIVEREF(__pyx_t_20);
  PyList_SET_ITEM(__pyx_t_25, 0, __pyx_t_20);
  __Pyx_GIVEREF(__pyx_t_24);
  PyList_SET_ITEM(__pyx_t_25, 1, __pyx_t_24);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_25, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_25, 3, __pyx_t_4);
  __pyx_t_20 = 0;
  __pyx_t_24 = 0;
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_25); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
    __Pyx_GOTREF(__pyx_t_11);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_25);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_25);
    __pyx_t_25 = 0;
    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 167, __pyx_L1_error)
  __pyx_t_26 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer, (PyObject*)__pyx_v_bnds, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_bnds.diminfo[0].strides = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bnds.diminfo[0].shape = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 167, __pyx_L1_error)
  }
  __pyx_t_26 = 0;
  __pyx_v_bnds = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":169
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)             # <<<<<<<<<<<<<<
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:
 */
  __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_average); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_v_xdata));
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 169, __pyx_L1_error)
  __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, __pyx_t_5); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_27 = __pyx_PyFloat_AsFloat(__pyx_t_25); if (unlikely((__pyx_t_27 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 169, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
  __pyx_v_average = __pyx_t_27;

  /* "pyquant/cpeaks.pyx":170
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))             # <<<<<<<<<<<<<<
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_average); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyNumber_Subtract(((PyObject *)__pyx_v_xdata), __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Power(__pyx_t_4, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 170, __pyx_L1_error)
  __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_24);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_25 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_24); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 170, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
    __Pyx_GOTREF(__pyx_t_25);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
    __Pyx_GIVEREF(__pyx_t_24);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_24);
    __pyx_t_24 = 0;
    __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, NULL); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 170, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_25);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_27 = __pyx_PyFloat_AsFloat(__pyx_t_25); if (unlikely((__pyx_t_27 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
  __pyx_v_variance = __pyx_t_27;

  /* "pyquant/cpeaks.pyx":171
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:             # <<<<<<<<<<<<<<
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 */
  __pyx_t_17 = ((__pyx_v_variance == 0.0) != 0);
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":173
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:             # <<<<<<<<<<<<<<
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 */
    __pyx_t_17 = ((__pyx_v_peak_index >= 1) != 0);
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":174
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])             # <<<<<<<<<<<<<<
 *         elif peak_index < len(xdata):
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 */
      __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 174, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_abs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_28 = (__pyx_v_peak_index - 1);
      __pyx_t_12 = -1;
      if (__pyx_t_28 < 0) {
        __pyx_t_28 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        if (unlikely(__pyx_t_28 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 174, __pyx_L1_error)
      }
      __pyx_t_11 = PyFloat_FromDouble((__pyx_v_peak_loc - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_xdata.diminfo[0].strides)))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 174, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_24 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_24)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_24);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_24) {
        __pyx_t_25 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 174, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_25);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 174, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_24); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_24); __pyx_t_24 = NULL;
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_11);
        __pyx_t_11 = 0;
        __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 174, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_25);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_27 = __pyx_PyFloat_AsFloat(__pyx_t_25); if (unlikely((__pyx_t_27 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 174, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
      __pyx_v_variance = __pyx_t_27;

      /* "pyquant/cpeaks.pyx":173
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:             # <<<<<<<<<<<<<<
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 */
      goto __pyx_L8;
    }

    /* "pyquant/cpeaks.pyx":175
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 *         else:
 */
    __pyx_t_29 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_29 == -1)) __PYX_ERR(0, 175, __pyx_L1_error)
    __pyx_t_17 = ((__pyx_v_peak_index < __pyx_t_29) != 0);
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":176
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)             # <<<<<<<<<<<<<<
 *         else:
 *             # we have only 1 data point, most RT's fall into this width
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_abs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 176, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_30 = (__pyx_v_peak_index + 1);
      __pyx_t_12 = -1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 176, __pyx_L1_error)
      }
      __pyx_t_4 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_loc)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_11 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_25 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_25);
      } else {
        __pyx_t_24 = PyTuple_New(1+1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_24);
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_11); __pyx_t_11 = NULL;
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_24, 0+1, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_24, NULL); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_25);
        __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_27 = __pyx_PyFloat_AsFloat(__pyx_t_25); if (unlikely((__pyx_t_27 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 176, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
      __pyx_v_variance = __pyx_t_27;

      /* "pyquant/cpeaks.pyx":175
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 *         else:
 */
      goto __pyx_L8;
    }

    /* "pyquant/cpeaks.pyx":179
 *         else:
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05             # <<<<<<<<<<<<<<
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min
 */
    /*else*/ {
      __pyx_v_variance = 0.05;
    }
    __pyx_L8:;

    /* "pyquant/cpeaks.pyx":171
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:             # <<<<<<<<<<<<<<
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 */
  }

  /* "pyquant/cpeaks.pyx":180
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:             # <<<<<<<<<<<<<<
 *         variance = xdata[peak_index]-peak_min
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 */
  __pyx_t_31 = __pyx_v_peak_index;
  __pyx_t_12 = -1;
  if (__pyx_t_31 < 0) {
    __pyx_t_31 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_31 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 180, __pyx_L1_error)
  }
  __pyx_t_32 = ((__pyx_v_variance > ((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_min)) != 0);
  if (!__pyx_t_32) {
  } else {
    __pyx_t_17 = __pyx_t_32;
    goto __pyx_L10_bool_binop_done;
  }
  __pyx_t_33 = __pyx_v_peak_index;
  __pyx_t_12 = -1;
  if (__pyx_t_33 < 0) {
    __pyx_t_33 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_33 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_33 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 180, __pyx_L1_error)
  }
  __pyx_t_32 = ((__pyx_v_variance > (__pyx_v_peak_max - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_33, __pyx_pybuffernd_xdata.diminfo[0].strides)))) != 0);
  __pyx_t_17 = __pyx_t_32;
  __pyx_L10_bool_binop_done:;
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":181
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)
 */
    __pyx_t_34 = __pyx_v_peak_index;
    __pyx_t_12 = -1;
    if (__pyx_t_34 < 0) {
      __pyx_t_34 += __pyx_pybuffernd_xdata.diminfo[0].shape;
      if (unlikely(__pyx_t_34 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_34 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 181, __pyx_L1_error)
    }
    __pyx_v_variance = ((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_min);

    /* "pyquant/cpeaks.pyx":180
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:             # <<<<<<<<<<<<<<
 *         variance = xdata[peak_index]-peak_min
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 */
  }

  /* "pyquant/cpeaks.pyx":182
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])             # <<<<<<<<<<<<<<
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000, 'ftol': 1e-20}
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_24);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_peak_loc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_6 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_20 = PyList_New(4); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_20, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_11);
  PyList_SET_ITEM(__pyx_t_20, 2, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_20, 3, __pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_11 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_24))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_24);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_24);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_24, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_25 = __Pyx_PyObject_CallOneArg(__pyx_t_24, __pyx_t_20); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_GOTREF(__pyx_t_25);
  } else {
    __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_6); __pyx_t_6 = NULL;
    __Pyx_GIVEREF(__pyx_t_20);
    PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_20);
    __pyx_t_20 = 0;
    __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_24, __pyx_t_11, NULL); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_25);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  }
  __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
  if (!(likely(((__pyx_t_25) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_25, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 182, __pyx_L1_error)
  __pyx_t_35 = ((PyArrayObject *)__pyx_t_25);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_t_35, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_guess = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_guess.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 182, __pyx_L1_error)
    } else {__pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_35 = 0;
  __pyx_v_guess = ((PyArrayObject *)__pyx_t_25);
  __pyx_t_25 = 0;

  /* "pyquant/cpeaks.pyx":183
 *         variance = xdata[peak_index]-peak_min
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)             # <<<<<<<<<<<<<<
 *     base_opts = {'maxiter': 1000, 'ftol': 1e-20}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 */
  __pyx_t_25 = PyTuple_New(2); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 183, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_25, 0, ((PyObject *)__pyx_v_xdata));
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
  PyTuple_SET_ITEM(__pyx_t_25, 1, ((PyObject *)__pyx_v_ydata));
  __pyx_v_args = ((PyObject*)__pyx_t_25);
  __pyx_t_25 = 0;

  /* "pyquant/cpeaks.pyx":184
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000, 'ftol': 1e-20}             # <<<<<<<<<<<<<<
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)
 */
  __pyx_t_25 = PyDict_New(); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  if (PyDict_SetItem(__pyx_t_25, __pyx_n_s_maxiter, __pyx_int_1000) < 0) __PYX_ERR(0, 184, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_25, __pyx_n_s_ftol, __pyx_float_1eneg_20) < 0) __PYX_ERR(0, 184, __pyx_L1_error)
  __pyx_v_base_opts = ((PyObject*)__pyx_t_25);
  __pyx_t_25 = 0;

  /* "pyquant/cpeaks.pyx":185
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000, 'ftol': 1e-20}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]             # <<<<<<<<<<<<<<
 *     routine, opts = routines.pop(0)
 *     try:
 */
  __pyx_t_25 = PyTuple_New(2); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_25);
  __Pyx_INCREF(__pyx_n_s_SLSQP);
  __Pyx_GIVEREF(__pyx_n_s_SLSQP);
  PyTuple_SET_ITEM(__pyx_t_25, 0, __pyx_n_s_SLSQP);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_25, 1, __pyx_v_base_opts);
  __pyx_t_24 = PyTuple_New(2); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_24);
  __Pyx_INCREF(__pyx_n_s_TNC);
  __Pyx_GIVEREF(__pyx_n_s_TNC);
  PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_n_s_TNC);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_v_base_opts);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_INCREF(__pyx_kp_s_L_BFGS_B);
  __Pyx_GIVEREF(__pyx_kp_s_L_BFGS_B);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_kp_s_L_BFGS_B);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_base_opts);
  __pyx_t_20 = PyList_New(3); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_GIVEREF(__pyx_t_25);
  PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_25);
  __Pyx_GIVEREF(__pyx_t_24);
  PyList_SET_ITEM(__pyx_t_20, 1, __pyx_t_24);
  __Pyx_GIVEREF(__pyx_t_11);
  PyList_SET_ITEM(__pyx_t_20, 2, __pyx_t_11);
  __pyx_t_25 = 0;
  __pyx_t_24 = 0;
  __pyx_t_11 = 0;
  __pyx_v_routines = ((PyObject*)__pyx_t_20);
  __pyx_t_20 = 0;

  /* "pyquant/cpeaks.pyx":186
 *     base_opts = {'maxiter': 1000, 'ftol': 1e-20}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)             # <<<<<<<<<<<<<<
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 */
  __pyx_t_20 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 186, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  if ((likely(PyTuple_CheckExact(__pyx_t_20))) || (PyList_CheckExact(__pyx_t_20))) {
    PyObject* sequence = __pyx_t_20;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 186, __pyx_L1_error)
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_24 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_24 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx_t_24);
    #else
    __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_24 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_24);
    #endif
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_25 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_25);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_36 = Py_TYPE(__pyx_t_25)->tp_iternext;
    index = 0; __pyx_t_11 = __pyx_t_36(__pyx_t_25); if (unlikely(!__pyx_t_11)) goto __pyx_L12_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_11);
    index = 1; __pyx_t_24 = __pyx_t_36(__pyx_t_25); if (unlikely(!__pyx_t_24)) goto __pyx_L12_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_24);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_36(__pyx_t_25), 2) < 0) __PYX_ERR(0, 186, __pyx_L1_error)
    __pyx_t_36 = NULL;
    __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
    goto __pyx_L13_unpacking_done;
    __pyx_L12_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
    __pyx_t_36 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 186, __pyx_L1_error)
    __pyx_L13_unpacking_done:;
  }
  __pyx_v_routine = __pyx_t_11;
  __pyx_t_11 = 0;
  __pyx_v_opts = __pyx_t_24;
  __pyx_t_24 = 0;

  /* "pyquant/cpeaks.pyx":187
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 *     except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_8);
    __Pyx_XGOTREF(__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_10);
    /*try:*/ {

      /* "pyquant/cpeaks.pyx":188
 *     routine, opts = routines.pop(0)
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         print 'fitting error'
 */
      __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_minimize); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_func); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_20);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_20);
      __Pyx_INCREF(((PyObject *)__pyx_v_guess));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_guess));
      PyTuple_SET_ITEM(__pyx_t_11, 1, ((PyObject *)__pyx_v_guess));
      __Pyx_INCREF(__pyx_v_args);
      __Pyx_GIVEREF(__pyx_v_args);
      PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_args);
      __pyx_t_20 = 0;
      __pyx_t_20 = PyDict_New(); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_bounds, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 188, __pyx_L14_error)
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 188, __pyx_L14_error)
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 188, __pyx_L14_error)
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_tol, __pyx_float_1eneg_20) < 0) __PYX_ERR(0, 188, __pyx_L14_error)
      __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_24, __pyx_t_11, __pyx_t_20); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_25);
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 188, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_GIVEREF(__pyx_t_25);
      PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_25);
      __pyx_t_25 = 0;
      __pyx_v_results = ((PyObject*)__pyx_t_20);
      __pyx_t_20 = 0;

      /* "pyquant/cpeaks.pyx":187
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 *     except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    goto __pyx_L21_try_end;
    __pyx_L14_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
    __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;

    /* "pyquant/cpeaks.pyx":189
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         print 'fitting error'
 *         import traceback
 */
    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_12) {
      __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_20, &__pyx_t_25, &__pyx_t_11) < 0) __PYX_ERR(0, 189, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_GOTREF(__pyx_t_25);
      __Pyx_GOTREF(__pyx_t_11);

      /* "pyquant/cpeaks.pyx":190
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 *     except ValueError:
 *         print 'fitting error'             # <<<<<<<<<<<<<<
 *         import traceback
 *         print traceback.format_exc()
 */
      if (__Pyx_PrintOne(0, __pyx_kp_s_fitting_error) < 0) __PYX_ERR(0, 190, __pyx_L16_except_error)

      /* "pyquant/cpeaks.pyx":191
 *     except ValueError:
 *         print 'fitting error'
 *         import traceback             # <<<<<<<<<<<<<<
 *         print traceback.format_exc()
 *         print peak_loc
 */
      __pyx_t_24 = __Pyx_Import(__pyx_n_s_traceback, 0, -1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 191, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_24);
      __pyx_v_traceback = __pyx_t_24;
      __pyx_t_24 = 0;

      /* "pyquant/cpeaks.pyx":192
 *         print 'fitting error'
 *         import traceback
 *         print traceback.format_exc()             # <<<<<<<<<<<<<<
 *         print peak_loc
 *         print xdata.tolist()
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_traceback, __pyx_n_s_format_exc); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 192, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_24 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 192, __pyx_L16_except_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_24 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 192, __pyx_L16_except_error)
      }
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_24) < 0) __PYX_ERR(0, 192, __pyx_L16_except_error)
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;

      /* "pyquant/cpeaks.pyx":193
 *         import traceback
 *         print traceback.format_exc()
 *         print peak_loc             # <<<<<<<<<<<<<<
 *         print xdata.tolist()
 *         print ydata.tolist()
 */
      __pyx_t_24 = PyFloat_FromDouble(__pyx_v_peak_loc); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 193, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_24);
      if (__Pyx_PrintOne(0, __pyx_t_24) < 0) __PYX_ERR(0, 193, __pyx_L16_except_error)
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;

      /* "pyquant/cpeaks.pyx":194
 *         print traceback.format_exc()
 *         print peak_loc
 *         print xdata.tolist()             # <<<<<<<<<<<<<<
 *         print ydata.tolist()
 *         print bnds
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_xdata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 194, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_24 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 194, __pyx_L16_except_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_24 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 194, __pyx_L16_except_error)
      }
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_24) < 0) __PYX_ERR(0, 194, __pyx_L16_except_error)
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;

      /* "pyquant/cpeaks.pyx":195
 *         print peak_loc
 *         print xdata.tolist()
 *         print ydata.tolist()             # <<<<<<<<<<<<<<
 *         print bnds
 *         results = []
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_24 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 195, __pyx_L16_except_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_24 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 195, __pyx_L16_except_error)
      }
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_24) < 0) __PYX_ERR(0, 195, __pyx_L16_except_error)
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;

      /* "pyquant/cpeaks.pyx":196
 *         print xdata.tolist()
 *         print ydata.tolist()
 *         print bnds             # <<<<<<<<<<<<<<
 *         results = []
 *     while routines:
 */
      if (__Pyx_PrintOne(0, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 196, __pyx_L16_except_error)

      /* "pyquant/cpeaks.pyx":197
 *         print ydata.tolist()
 *         print bnds
 *         results = []             # <<<<<<<<<<<<<<
 *     while routines:
 *         routine, opts = routines.pop(0)
 */
      __pyx_t_24 = PyList_New(0); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 197, __pyx_L16_except_error)
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_XDECREF_SET(__pyx_v_results, ((PyObject*)__pyx_t_24));
      __pyx_t_24 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L15_exception_handled;
    }
    goto __pyx_L16_except_error;
    __pyx_L16_except_error:;

    /* "pyquant/cpeaks.pyx":187
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20)]
 *     except ValueError:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L1_error;
    __pyx_L15_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    __pyx_L21_try_end:;
  }

  /* "pyquant/cpeaks.pyx":198
 *         print bnds
 *         results = []
 *     while routines:             # <<<<<<<<<<<<<<
 *         routine, opts = routines.pop(0)
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20))
 */
  while (1) {
    __pyx_t_17 = (__pyx_v_routines != Py_None) && (PyList_GET_SIZE(__pyx_v_routines) != 0);
    if (!__pyx_t_17) break;

    /* "pyquant/cpeaks.pyx":199
 *         results = []
 *     while routines:
 *         routine, opts = routines.pop(0)             # <<<<<<<<<<<<<<
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20))
 *     # cdef int n = len(xdata)
 */
    __pyx_t_11 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
      PyObject* sequence = __pyx_t_11;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 199, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_25 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_25 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_25);
      __Pyx_INCREF(__pyx_t_20);
      #else
      __pyx_t_25 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_25);
      __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      #endif
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_24 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_24);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_36 = Py_TYPE(__pyx_t_24)->tp_iternext;
      index = 0; __pyx_t_25 = __pyx_t_36(__pyx_t_24); if (unlikely(!__pyx_t_25)) goto __pyx_L26_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_25);
      index = 1; __pyx_t_20 = __pyx_t_36(__pyx_t_24); if (unlikely(!__pyx_t_20)) goto __pyx_L26_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_20);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_36(__pyx_t_24), 2) < 0) __PYX_ERR(0, 199, __pyx_L1_error)
      __pyx_t_36 = NULL;
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
      goto __pyx_L27_unpacking_done;
      __pyx_L26_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
      __pyx_t_36 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 199, __pyx_L1_error)
      __pyx_L27_unpacking_done:;
    }
    __Pyx_DECREF_SET(__pyx_v_routine, __pyx_t_25);
    __pyx_t_25 = 0;
    __Pyx_DECREF_SET(__pyx_v_opts, __pyx_t_20);
    __pyx_t_20 = 0;

    /* "pyquant/cpeaks.pyx":200
 *     while routines:
 *         routine, opts = routines.pop(0)
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20))             # <<<<<<<<<<<<<<
 *     # cdef int n = len(xdata)
 *     cdef float lowest = -1
 */
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_minimize); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_func); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_25 = PyTuple_New(3); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_25);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_25, 0, __pyx_t_11);
    __Pyx_INCREF(((PyObject *)__pyx_v_guess));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_guess));
    PyTuple_SET_ITEM(__pyx_t_25, 1, ((PyObject *)__pyx_v_guess));
    __Pyx_INCREF(__pyx_v_args);
    __Pyx_GIVEREF(__pyx_v_args);
    PyTuple_SET_ITEM(__pyx_t_25, 2, __pyx_v_args);
    __pyx_t_11 = 0;
    __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_bounds, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 200, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 200, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 200, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_tol, __pyx_float_1eneg_20) < 0) __PYX_ERR(0, 200, __pyx_L1_error)
    __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_25, __pyx_t_11); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_24);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_37 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_24); if (unlikely(__pyx_t_37 == -1)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
  }

  /* "pyquant/cpeaks.pyx":202
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, tol=1e-20))
 *     # cdef int n = len(xdata)
 *     cdef float lowest = -1             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t] best
 *     best = results[0].x
 */
  __pyx_v_lowest = -1.0;

  /* "pyquant/cpeaks.pyx":204
 *     cdef float lowest = -1
 *     cdef np.ndarray[FLOAT_t] best
 *     best = results[0].x             # <<<<<<<<<<<<<<
 * 
 *     for i in results:
 */
  __pyx_t_24 = __Pyx_GetItemInt_List(__pyx_v_results, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_24);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_24, __pyx_n_s_x); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 204, __pyx_L1_error)
  __pyx_t_38 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_best.rcbuffer->pybuffer);
    __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best.rcbuffer->pybuffer, (PyObject*)__pyx_t_38, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_12 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best.rcbuffer->pybuffer, (PyObject*)__pyx_v_best, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_best.diminfo[0].strides = __pyx_pybuffernd_best.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_best.diminfo[0].shape = __pyx_pybuffernd_best.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 204, __pyx_L1_error)
  }
  __pyx_t_38 = 0;
  __pyx_v_best = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":206
 *     best = results[0].x
 * 
 *     for i in results:             # <<<<<<<<<<<<<<
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 */
  __pyx_t_11 = __pyx_v_results; __Pyx_INCREF(__pyx_t_11); __pyx_t_29 = 0;
  for (;;) {
    if (__pyx_t_29 >= PyList_GET_SIZE(__pyx_t_11)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_24 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_29); __Pyx_INCREF(__pyx_t_24); __pyx_t_29++; if (unlikely(0 < 0)) __PYX_ERR(0, 206, __pyx_L1_error)
    #else
    __pyx_t_24 = PySequence_ITEM(__pyx_t_11, __pyx_t_29); __pyx_t_29++; if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_24);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_24);
    __pyx_t_24 = 0;

    /* "pyquant/cpeaks.pyx":207
 * 
 *     for i in results:
 *         if within_bounds(i.x, bnds):             # <<<<<<<<<<<<<<
 *             if lowest == -1 or i.fun < lowest:
 *                 best = i.x
 */
    __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_v_i, __pyx_n_s_x); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_24);
    if (!(likely(((__pyx_t_24) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_24, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 207, __pyx_L1_error)
    __pyx_t_17 = (__pyx_f_7pyquant_6cpeaks_within_bounds(((PyArrayObject *)__pyx_t_24), ((PyArrayObject *)__pyx_v_bnds)) != 0);
    __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":208
 *     for i in results:
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:             # <<<<<<<<<<<<<<
 *                 best = i.x
 *     # cdef int k = len(best.x)
 */
      __pyx_t_32 = ((__pyx_v_lowest == -1.0) != 0);
      if (!__pyx_t_32) {
      } else {
        __pyx_t_17 = __pyx_t_32;
        goto __pyx_L32_bool_binop_done;
      }
      __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_v_i, __pyx_n_s_fun); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_24);
      __pyx_t_25 = PyFloat_FromDouble(__pyx_v_lowest); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_25);
      __pyx_t_20 = PyObject_RichCompare(__pyx_t_24, __pyx_t_25, Py_LT); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
      __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
      __pyx_t_32 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely(__pyx_t_32 < 0)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_t_17 = __pyx_t_32;
      __pyx_L32_bool_binop_done:;
      if (__pyx_t_17) {

        /* "pyquant/cpeaks.pyx":209
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 *                 best = i.x             # <<<<<<<<<<<<<<
 *     # cdef int k = len(best.x)
 *     # cdef float bic = n*np.log(best.fun/n)+k+np.log(n)
 */
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_i, __pyx_n_s_x); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 209, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        if (!(likely(((__pyx_t_20) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_20, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 209, __pyx_L1_error)
        __pyx_t_38 = ((PyArrayObject *)__pyx_t_20);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_best.rcbuffer->pybuffer);
          __pyx_t_12 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best.rcbuffer->pybuffer, (PyObject*)__pyx_t_38, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_12 < 0)) {
            PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best.rcbuffer->pybuffer, (PyObject*)__pyx_v_best, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
            }
          }
          __pyx_pybuffernd_best.diminfo[0].strides = __pyx_pybuffernd_best.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_best.diminfo[0].shape = __pyx_pybuffernd_best.rcbuffer->pybuffer.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 209, __pyx_L1_error)
        }
        __pyx_t_38 = 0;
        __Pyx_DECREF_SET(__pyx_v_best, ((PyArrayObject *)__pyx_t_20));
        __pyx_t_20 = 0;

        /* "pyquant/cpeaks.pyx":208
 *     for i in results:
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:             # <<<<<<<<<<<<<<
 *                 best = i.x
 *     # cdef int k = len(best.x)
 */
      }

      /* "pyquant/cpeaks.pyx":207
 * 
 *     for i in results:
 *         if within_bounds(i.x, bnds):             # <<<<<<<<<<<<<<
 *             if lowest == -1 or i.fun < lowest:
 *                 best = i.x
 */
    }

    /* "pyquant/cpeaks.pyx":206
 *     best = results[0].x
 * 
 *     for i in results:             # <<<<<<<<<<<<<<
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 */
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":213
 *     # cdef float bic = n*np.log(best.fun/n)+k+np.log(n)
 *     # best.bic = bic
 *     return best             # <<<<<<<<<<<<<<
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_best));
  __pyx_r = ((PyArrayObject *)__pyx_v_best);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":140
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_24);
  __Pyx_XDECREF(__pyx_t_25);
  { 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_best.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_best.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_bnds);
  __Pyx_XDECREF(__pyx_v_min_spacing);
  __Pyx_XDECREF(__pyx_v_lb);
  __Pyx_XDECREF(__pyx_v_rb);
  __Pyx_XDECREF((PyObject *)__pyx_v_guess);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_base_opts);
  __Pyx_XDECREF(__pyx_v_routines);
  __Pyx_XDECREF(__pyx_v_routine);
  __Pyx_XDECREF(__pyx_v_opts);
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XDECREF(__pyx_v_traceback);
  __Pyx_XDECREF((PyObject *)__pyx_v_best);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF((PyObject *)__pyx_v_xdata);
  __Pyx_XDECREF((PyObject *)__pyx_v_ydata);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_13fixedMeanFit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_13fixedMeanFit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  int __pyx_v_peak_index;
  PyObject *__pyx_v_debug = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fixedMeanFit (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_ydata,&__pyx_n_s_peak_index,&__pyx_n_s_debug,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pyquant/cpeaks.pyx":141
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 *                                        int peak_index=1, debug=False):             # <<<<<<<<<<<<<<
 *     cdef float rel_peak = ydata[peak_index]
 *     cdef float peak_loc = xdata[peak_index]
 */
    values[3] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("fixedMeanFit", 0, 2, 4, 1); __PYX_ERR(0, 140, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_peak_index);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_debug);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fixedMeanFit") < 0)) __PYX_ERR(0, 140, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_ydata = ((PyArrayObject *)values[1]);
    if (values[2]) {
      __pyx_v_peak_index = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_peak_index == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 141, __pyx_L3_error)
    } else {
      __pyx_v_peak_index = ((int)1);
    }
    __pyx_v_debug = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fixedMeanFit", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 140, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 140, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 140, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_12fixedMeanFit(__pyx_self, __pyx_v_xdata, __pyx_v_ydata, __pyx_v_peak_index, __pyx_v_debug);

  /* "pyquant/cpeaks.pyx":140
 *     return residual
 * 
 * cpdef np.ndarray[FLOAT_t] fixedMeanFit(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak = ydata[peak_index]
 */

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_12fixedMeanFit(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, int __pyx_v_peak_index, PyObject *__pyx_v_debug) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit __pyx_t_2;
  __Pyx_RefNannySetupContext("fixedMeanFit", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 140, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 140, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.peak_index = __pyx_v_peak_index;
  __pyx_t_2.debug = __pyx_v_debug;
  __pyx_t_1 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_fixedMeanFit(__pyx_v_xdata, __pyx_v_ydata, 0, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":215
 *     return best
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak, mval
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_15fixedMeanFit2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_fixedMeanFit2(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit2 *__pyx_optional_args) {
  int __pyx_v_peak_index = ((int)1);

  /* "pyquant/cpeaks.pyx":216
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 *                                        int peak_index=1, debug=False):             # <<<<<<<<<<<<<<
 *     cdef float rel_peak, mval
 *     cdef float peak_loc = xdata[peak_index]
 */
  PyObject *__pyx_v_debug = ((PyObject *)Py_False);
  float __pyx_v_rel_peak;
  float __pyx_v_mval;
  float __pyx_v_peak_loc;
  int __pyx_v_peak_left;
  int __pyx_v_peak_right;
  PyArrayObject *__pyx_v_conv_y = 0;
  float __pyx_v_peak_min;
  float __pyx_v_peak_max;
  float __pyx_v_average;
  float __pyx_v_variance;
  PyArrayObject *__pyx_v_bnds = 0;
  PyObject *__pyx_v_min_spacing = NULL;
  PyObject *__pyx_v_lb = NULL;
  PyObject *__pyx_v_rb = NULL;
  PyArrayObject *__pyx_v_guess = 0;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_base_opts = NULL;
  PyObject *__pyx_v_routines = NULL;
  PyObject *__pyx_v_routine = NULL;
  PyObject *__pyx_v_opts = NULL;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_v_traceback = NULL;
  float __pyx_v_lowest;
  PyObject *__pyx_v_best_fit = NULL;
  PyObject *__pyx_v_i = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bnds;
  __Pyx_Buffer __pyx_pybuffer_bnds;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_conv_y;
  __Pyx_Buffer __pyx_pybuffer_conv_y;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_guess;
  __Pyx_Buffer __pyx_pybuffer_guess;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  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;
  float __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyArrayObject *__pyx_t_14 = NULL;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  __pyx_t_7pyquant_6cpeaks_FLOAT_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  __pyx_t_7pyquant_6cpeaks_FLOAT_t __pyx_t_19;
  int __pyx_t_20;
  PyArrayObject *__pyx_t_21 = NULL;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  PyObject *__pyx_t_26 = NULL;
  PyObject *__pyx_t_27 = NULL;
  PyArrayObject *__pyx_t_28 = NULL;
  Py_ssize_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  int __pyx_t_32;
  Py_ssize_t __pyx_t_33;
  Py_ssize_t __pyx_t_34;
  PyArrayObject *__pyx_t_35 = NULL;
  PyObject *(*__pyx_t_36)(PyObject *);
  int __pyx_t_37;
  __Pyx_RefNannySetupContext("fixedMeanFit2", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_peak_index = __pyx_optional_args->peak_index;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_debug = __pyx_optional_args->debug;
      }
    }
  }
  __Pyx_INCREF((PyObject *)__pyx_v_xdata);
  __Pyx_INCREF((PyObject *)__pyx_v_ydata);
  __pyx_pybuffer_conv_y.pybuffer.buf = NULL;
  __pyx_pybuffer_conv_y.refcount = 0;
  __pyx_pybuffernd_conv_y.data = NULL;
  __pyx_pybuffernd_conv_y.rcbuffer = &__pyx_pybuffer_conv_y;
  __pyx_pybuffer_bnds.pybuffer.buf = NULL;
  __pyx_pybuffer_bnds.refcount = 0;
  __pyx_pybuffernd_bnds.data = NULL;
  __pyx_pybuffernd_bnds.rcbuffer = &__pyx_pybuffer_bnds;
  __pyx_pybuffer_guess.pybuffer.buf = NULL;
  __pyx_pybuffer_guess.refcount = 0;
  __pyx_pybuffernd_guess.data = NULL;
  __pyx_pybuffernd_guess.rcbuffer = &__pyx_pybuffer_guess;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":218
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak, mval
 *     cdef float peak_loc = xdata[peak_index]             # <<<<<<<<<<<<<<
 *     cdef int peak_left, peak_right
 *     cdef np.ndarray[FLOAT_t, ndim=1] conv_y
 */
  __pyx_t_1 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 218, __pyx_L1_error)
  }
  __pyx_v_peak_loc = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_xdata.diminfo[0].strides));

  /* "pyquant/cpeaks.pyx":224
 *     cdef np.ndarray[FLOAT_t, ndim=1] bnds
 * 
 *     mval = ydata.max()             # <<<<<<<<<<<<<<
 *     conv_y = gaussian_filter1d(convolve(ydata, kaiser(10, 14), mode='same'), 3, mode='constant')
 *     rel_peak = conv_y[peak_index]/conv_y.max()
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_max); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_mval = __pyx_t_6;

  /* "pyquant/cpeaks.pyx":225
 * 
 *     mval = ydata.max()
 *     conv_y = gaussian_filter1d(convolve(ydata, kaiser(10, 14), mode='same'), 3, mode='constant')             # <<<<<<<<<<<<<<
 *     rel_peak = conv_y[peak_index]/conv_y.max()
 *     ydata /= mval
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gaussian_filter1d); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_convolve); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_kaiser); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_mode, __pyx_n_s_same) < 0) __PYX_ERR(0, 225, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_3);
  __pyx_t_8 = 0;
  __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_mode, __pyx_n_s_constant) < 0) __PYX_ERR(0, 225, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 225, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_conv_y.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_conv_y.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_conv_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_conv_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
    }
    __pyx_pybuffernd_conv_y.diminfo[0].strides = __pyx_pybuffernd_conv_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_conv_y.diminfo[0].shape = __pyx_pybuffernd_conv_y.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 225, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_conv_y = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":226
 *     mval = ydata.max()
 *     conv_y = gaussian_filter1d(convolve(ydata, kaiser(10, 14), mode='same'), 3, mode='constant')
 *     rel_peak = conv_y[peak_index]/conv_y.max()             # <<<<<<<<<<<<<<
 *     ydata /= mval
 *     peak_left, peak_right = 0, len(xdata)#findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)
 */
  __pyx_t_13 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_13 < 0) {
    __pyx_t_13 += __pyx_pybuffernd_conv_y.diminfo[0].shape;
    if (unlikely(__pyx_t_13 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_13 >= __pyx_pybuffernd_conv_y.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 226, __pyx_L1_error)
  }
  __pyx_t_5 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_conv_y.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_conv_y.diminfo[0].strides))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_conv_y), __pyx_n_s_max); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 226, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_7); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_rel_peak = __pyx_t_6;

  /* "pyquant/cpeaks.pyx":227
 *     conv_y = gaussian_filter1d(convolve(ydata, kaiser(10, 14), mode='same'), 3, mode='constant')
 *     rel_peak = conv_y[peak_index]/conv_y.max()
 *     ydata /= mval             # <<<<<<<<<<<<<<
 *     peak_left, peak_right = 0, len(xdata)#findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)
 *     peak_min, peak_max = xdata[0], xdata[-1]
 */
  __pyx_t_7 = PyFloat_FromDouble(__pyx_v_mval); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_ydata), __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __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, 227, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_12, __pyx_t_11, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 227, __pyx_L1_error)
  }
  __pyx_t_14 = 0;
  __Pyx_DECREF_SET(__pyx_v_ydata, ((PyArrayObject *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "pyquant/cpeaks.pyx":228
 *     rel_peak = conv_y[peak_index]/conv_y.max()
 *     ydata /= mval
 *     peak_left, peak_right = 0, len(xdata)#findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)             # <<<<<<<<<<<<<<
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 */
  __pyx_t_2 = 0;
  __pyx_t_15 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 228, __pyx_L1_error)
  __pyx_v_peak_left = __pyx_t_2;
  __pyx_v_peak_right = __pyx_t_15;

  /* "pyquant/cpeaks.pyx":229
 *     ydata /= mval
 *     peak_left, peak_right = 0, len(xdata)#findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)
 *     peak_min, peak_max = xdata[0], xdata[-1]             # <<<<<<<<<<<<<<
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:
 */
  __pyx_t_16 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_16 < 0) {
    __pyx_t_16 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_16 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_16 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 229, __pyx_L1_error)
  }
  __pyx_t_17 = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_xdata.diminfo[0].strides));
  __pyx_t_18 = -1L;
  __pyx_t_2 = -1;
  if (__pyx_t_18 < 0) {
    __pyx_t_18 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_18 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 229, __pyx_L1_error)
  }
  __pyx_t_19 = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_xdata.diminfo[0].strides));
  __pyx_v_peak_min = __pyx_t_17;
  __pyx_v_peak_max = __pyx_t_19;

  /* "pyquant/cpeaks.pyx":231
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:             # <<<<<<<<<<<<<<
 *         peak_index -= peak_left-1
 *     else:
 */
  __pyx_t_20 = ((__pyx_v_peak_index == __pyx_v_peak_right) != 0);
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":232
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:
 *         peak_index -= peak_left-1             # <<<<<<<<<<<<<<
 *     else:
 *         peak_index -= peak_left
 */
    __pyx_v_peak_index = (__pyx_v_peak_index - (__pyx_v_peak_left - 1));

    /* "pyquant/cpeaks.pyx":231
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 *     if peak_index == peak_right:             # <<<<<<<<<<<<<<
 *         peak_index -= peak_left-1
 *     else:
 */
    goto __pyx_L3;
  }

  /* "pyquant/cpeaks.pyx":234
 *         peak_index -= peak_left-1
 *     else:
 *         peak_index -= peak_left             # <<<<<<<<<<<<<<
 *     if debug:
 *         print('left is', peak_left, 'right is', peak_right)
 */
  /*else*/ {
    __pyx_v_peak_index = (__pyx_v_peak_index - __pyx_v_peak_left);
  }
  __pyx_L3:;

  /* "pyquant/cpeaks.pyx":235
 *     else:
 *         peak_index -= peak_left
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('left is', peak_left, 'right is', peak_right)
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())
 */
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 235, __pyx_L1_error)
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":236
 *         peak_index -= peak_left
 *     if debug:
 *         print('left is', peak_left, 'right is', peak_right)             # <<<<<<<<<<<<<<
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())
 *         print('y', ydata.tolist(), 'becomes', ydata[peak_left:peak_right].tolist())
 */
    __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_peak_left); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 236, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_peak_right); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 236, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 236, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_kp_s_left_is);
    __Pyx_GIVEREF(__pyx_kp_s_left_is);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_s_left_is);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
    __Pyx_INCREF(__pyx_kp_s_right_is);
    __Pyx_GIVEREF(__pyx_kp_s_right_is);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_s_right_is);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_7);
    __pyx_t_8 = 0;
    __pyx_t_7 = 0;
    if (__Pyx_PrintOne(0, __pyx_t_5) < 0) __PYX_ERR(0, 236, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pyquant/cpeaks.pyx":237
 *     if debug:
 *         print('left is', peak_left, 'right is', peak_right)
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())             # <<<<<<<<<<<<<<
 *         print('y', ydata.tolist(), 'becomes', ydata[peak_left:peak_right].tolist())
 *     xdata = xdata[peak_left:peak_right]
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_xdata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(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_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 237, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else {
      __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 237, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_tolist); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_8) {
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else {
      __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_n_s_x);
    __Pyx_GIVEREF(__pyx_n_s_x);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_x);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
    __Pyx_INCREF(__pyx_n_s_becomes);
    __Pyx_GIVEREF(__pyx_n_s_becomes);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_n_s_becomes);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_7);
    __pyx_t_5 = 0;
    __pyx_t_7 = 0;
    if (__Pyx_PrintOne(0, __pyx_t_3) < 0) __PYX_ERR(0, 237, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":238
 *         print('left is', peak_left, 'right is', peak_right)
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())
 *         print('y', ydata.tolist(), 'becomes', ydata[peak_left:peak_right].tolist())             # <<<<<<<<<<<<<<
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_tolist); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 238, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 238, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_n_s_y);
    __Pyx_GIVEREF(__pyx_n_s_y);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_y);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
    __Pyx_INCREF(__pyx_n_s_becomes);
    __Pyx_GIVEREF(__pyx_n_s_becomes);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_n_s_becomes);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_7);
    __pyx_t_3 = 0;
    __pyx_t_7 = 0;
    if (__Pyx_PrintOne(0, __pyx_t_8) < 0) __PYX_ERR(0, 238, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pyquant/cpeaks.pyx":235
 *     else:
 *         peak_index -= peak_left
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('left is', peak_left, 'right is', peak_right)
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())
 */
  }

  /* "pyquant/cpeaks.pyx":239
 *         print('x', xdata.tolist(), 'becomes', xdata[peak_left:peak_right].tolist())
 *         print('y', ydata.tolist(), 'becomes', ydata[peak_left:peak_right].tolist())
 *     xdata = xdata[peak_left:peak_right]             # <<<<<<<<<<<<<<
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:
 */
  __pyx_t_8 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 239, __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, 239, __pyx_L1_error)
  __pyx_t_21 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
    }
    __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 239, __pyx_L1_error)
  }
  __pyx_t_21 = 0;
  __Pyx_DECREF_SET(__pyx_v_xdata, ((PyArrayObject *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "pyquant/cpeaks.pyx":240
 *         print('y', ydata.tolist(), 'becomes', ydata[peak_left:peak_right].tolist())
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]             # <<<<<<<<<<<<<<
 *     if ydata.sum() == 0:
 *         return None, None
 */
  __pyx_t_8 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_peak_left, __pyx_v_peak_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 240, __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, 240, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_12, __pyx_t_11, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 240, __pyx_L1_error)
  }
  __pyx_t_14 = 0;
  __Pyx_DECREF_SET(__pyx_v_ydata, ((PyArrayObject *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "pyquant/cpeaks.pyx":241
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:             # <<<<<<<<<<<<<<
 *         return None, None
 *     min_spacing = min(np.diff(xdata))/2
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_sum); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 241, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 241, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 241, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 241, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 241, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":242
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:
 *         return None, None             # <<<<<<<<<<<<<<
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_tuple__11);
    __pyx_r = __pyx_tuple__11;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":241
 *     xdata = xdata[peak_left:peak_right]
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:             # <<<<<<<<<<<<<<
 *         return None, None
 *     min_spacing = min(np.diff(xdata))/2
 */
  }

  /* "pyquant/cpeaks.pyx":243
 *     if ydata.sum() == 0:
 *         return None, None
 *     min_spacing = min(np.diff(xdata))/2             # <<<<<<<<<<<<<<
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_diff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_8) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_xdata)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8); __pyx_t_8 = NULL;
    __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_xdata));
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_min_spacing = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":244
 *         return None, None
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])             # <<<<<<<<<<<<<<
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_fabs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_22 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_22 < 0) {
    __pyx_t_22 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_22 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_22 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 244, __pyx_L1_error)
  }
  __pyx_t_7 = PyFloat_FromDouble((__pyx_v_peak_loc - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_xdata.diminfo[0].strides)))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_8) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); __pyx_t_8 = NULL;
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_lb = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":245
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)             # <<<<<<<<<<<<<<
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_fabs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_23 = -1L;
  __pyx_t_2 = -1;
  if (__pyx_t_23 < 0) {
    __pyx_t_23 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_23 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_23 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 245, __pyx_L1_error)
  }
  __pyx_t_5 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_loc)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 245, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 245, __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_5);
    PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 245, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_rb = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":246
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:             # <<<<<<<<<<<<<<
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_lb, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error)
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 246, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":247
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:
 *         lb = min_spacing*5             # <<<<<<<<<<<<<<
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 */
    __pyx_t_3 = PyNumber_Multiply(__pyx_v_min_spacing, __pyx_int_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 247, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_lb, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":246
 *     lb = np.fabs(peak_loc-xdata[0])
 *     rb = np.fabs(xdata[-1]-peak_loc)
 *     if lb < min_spacing:             # <<<<<<<<<<<<<<
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 */
  }

  /* "pyquant/cpeaks.pyx":248
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 *     if rb < min_spacing:             # <<<<<<<<<<<<<<
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_rb, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error)
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":249
 *         lb = min_spacing*5
 *     if rb < min_spacing:
 *         rb = min_spacing*5             # <<<<<<<<<<<<<<
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 *     #print bnds, xdata, peak_loc
 */
    __pyx_t_3 = PyNumber_Multiply(__pyx_v_min_spacing, __pyx_int_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_rb, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":248
 *     if lb < min_spacing:
 *         lb = min_spacing*5
 *     if rb < min_spacing:             # <<<<<<<<<<<<<<
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 */
  }

  /* "pyquant/cpeaks.pyx":250
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])             # <<<<<<<<<<<<<<
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (((__pyx_v_rel_peak > 0.0) != 0)) {
    __pyx_t_5 = PyFloat_FromDouble((__pyx_v_rel_peak * 0.75)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
    __Pyx_INCREF(__pyx_float_1_01);
    __Pyx_GIVEREF(__pyx_float_1_01);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_float_1_01);
    __pyx_t_5 = 0;
    __pyx_t_4 = __pyx_t_7;
    __pyx_t_7 = 0;
  } else {
    __Pyx_INCREF(__pyx_tuple__12);
    __pyx_t_4 = __pyx_tuple__12;
  }
  __pyx_t_24 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_24 < 0) {
    __pyx_t_24 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_24 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_24 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 250, __pyx_L1_error)
  }
  __pyx_t_7 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_25 = -1L;
  __pyx_t_2 = -1;
  if (__pyx_t_25 < 0) {
    __pyx_t_25 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_25 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_25 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 250, __pyx_L1_error)
  }
  __pyx_t_5 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_26 = PyTuple_New(2); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_26, 1, __pyx_t_5);
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_min_spacing);
  __Pyx_GIVEREF(__pyx_v_min_spacing);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_min_spacing);
  __Pyx_INCREF(__pyx_v_lb);
  __Pyx_GIVEREF(__pyx_v_lb);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_lb);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_v_min_spacing);
  __Pyx_GIVEREF(__pyx_v_min_spacing);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_min_spacing);
  __Pyx_INCREF(__pyx_v_rb);
  __Pyx_GIVEREF(__pyx_v_rb);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_rb);
  __pyx_t_27 = PyList_New(4); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_27, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_26);
  PyList_SET_ITEM(__pyx_t_27, 1, __pyx_t_26);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_27, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_27, 3, __pyx_t_7);
  __pyx_t_4 = 0;
  __pyx_t_26 = 0;
  __pyx_t_5 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_27); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
    __Pyx_GIVEREF(__pyx_t_27);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_27);
    __pyx_t_27 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 250, __pyx_L1_error)
  __pyx_t_28 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer, (PyObject*)__pyx_t_28, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer, (PyObject*)__pyx_v_bnds, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
    }
    __pyx_pybuffernd_bnds.diminfo[0].strides = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bnds.diminfo[0].shape = __pyx_pybuffernd_bnds.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 250, __pyx_L1_error)
  }
  __pyx_t_28 = 0;
  __pyx_v_bnds = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":252
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)             # <<<<<<<<<<<<<<
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_average); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_xdata));
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 252, __pyx_L1_error)
  __pyx_t_27 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
  __pyx_v_average = __pyx_t_6;

  /* "pyquant/cpeaks.pyx":253
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))             # <<<<<<<<<<<<<<
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_average); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = PyNumber_Subtract(((PyObject *)__pyx_v_xdata), __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Power(__pyx_t_7, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 253, __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, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 253, __pyx_L1_error)
  __pyx_t_26 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_27 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_26); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 253, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
    __Pyx_GOTREF(__pyx_t_27);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 253, __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_26);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_26);
    __pyx_t_26 = 0;
    __pyx_t_27 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 253, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
  __pyx_v_variance = __pyx_t_6;

  /* "pyquant/cpeaks.pyx":254
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:             # <<<<<<<<<<<<<<
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 */
  __pyx_t_20 = ((__pyx_v_variance == 0.0) != 0);
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":256
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:             # <<<<<<<<<<<<<<
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 */
    __pyx_t_20 = ((__pyx_v_peak_index >= 1) != 0);
    if (__pyx_t_20) {

      /* "pyquant/cpeaks.pyx":257
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])             # <<<<<<<<<<<<<<
 *         elif peak_index < len(xdata):
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_abs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_29 = (__pyx_v_peak_index - 1);
      __pyx_t_2 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_2 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
      if (unlikely(__pyx_t_2 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_2);
        __PYX_ERR(0, 257, __pyx_L1_error)
      }
      __pyx_t_3 = PyFloat_FromDouble((__pyx_v_peak_loc - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_xdata.diminfo[0].strides)))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_26 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_26 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_26)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_26);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (!__pyx_t_26) {
        __pyx_t_27 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 257, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_27);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 257, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_26); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_26); __pyx_t_26 = NULL;
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_27 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 257, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 257, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
      __pyx_v_variance = __pyx_t_6;

      /* "pyquant/cpeaks.pyx":256
 *     if variance == 0:
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:             # <<<<<<<<<<<<<<
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 */
      goto __pyx_L9;
    }

    /* "pyquant/cpeaks.pyx":258
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 *         else:
 */
    __pyx_t_15 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 258, __pyx_L1_error)
    __pyx_t_20 = ((__pyx_v_peak_index < __pyx_t_15) != 0);
    if (__pyx_t_20) {

      /* "pyquant/cpeaks.pyx":259
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)             # <<<<<<<<<<<<<<
 *         else:
 *             # we have only 1 data point, most RT's fall into this width
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_abs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_30 = (__pyx_v_peak_index + 1);
      __pyx_t_2 = -1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_2 = 0;
      } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
      if (unlikely(__pyx_t_2 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_2);
        __PYX_ERR(0, 259, __pyx_L1_error)
      }
      __pyx_t_7 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_loc)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_27 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 259, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_27);
      } else {
        __pyx_t_26 = PyTuple_New(1+1); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 259, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_26);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_26, 0+1, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_27 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_26, NULL); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 259, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
      __pyx_v_variance = __pyx_t_6;

      /* "pyquant/cpeaks.pyx":258
 *         if peak_index >= 1:
 *             variance = np.abs(peak_loc-xdata[peak_index-1])
 *         elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *             variance = np.abs(xdata[peak_index+1]-peak_loc)
 *         else:
 */
      goto __pyx_L9;
    }

    /* "pyquant/cpeaks.pyx":262
 *         else:
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05             # <<<<<<<<<<<<<<
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min
 */
    /*else*/ {
      __pyx_v_variance = 0.05;
    }
    __pyx_L9:;

    /* "pyquant/cpeaks.pyx":254
 *     average = np.average(xdata, weights=ydata)
 *     variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *     if variance == 0:             # <<<<<<<<<<<<<<
 *         # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *         if peak_index >= 1:
 */
  }

  /* "pyquant/cpeaks.pyx":263
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:             # <<<<<<<<<<<<<<
 *         variance = xdata[peak_index]-peak_min
 *     if variance < min_spacing:
 */
  __pyx_t_31 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_31 < 0) {
    __pyx_t_31 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_31 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 263, __pyx_L1_error)
  }
  __pyx_t_32 = ((__pyx_v_variance > ((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_min)) != 0);
  if (!__pyx_t_32) {
  } else {
    __pyx_t_20 = __pyx_t_32;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_33 = __pyx_v_peak_index;
  __pyx_t_2 = -1;
  if (__pyx_t_33 < 0) {
    __pyx_t_33 += __pyx_pybuffernd_xdata.diminfo[0].shape;
    if (unlikely(__pyx_t_33 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_33 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 263, __pyx_L1_error)
  }
  __pyx_t_32 = ((__pyx_v_variance > (__pyx_v_peak_max - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_33, __pyx_pybuffernd_xdata.diminfo[0].strides)))) != 0);
  __pyx_t_20 = __pyx_t_32;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":264
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min             # <<<<<<<<<<<<<<
 *     if variance < min_spacing:
 *         variance = min_spacing
 */
    __pyx_t_34 = __pyx_v_peak_index;
    __pyx_t_2 = -1;
    if (__pyx_t_34 < 0) {
      __pyx_t_34 += __pyx_pybuffernd_xdata.diminfo[0].shape;
      if (unlikely(__pyx_t_34 < 0)) __pyx_t_2 = 0;
    } else if (unlikely(__pyx_t_34 >= __pyx_pybuffernd_xdata.diminfo[0].shape)) __pyx_t_2 = 0;
    if (unlikely(__pyx_t_2 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_2);
      __PYX_ERR(0, 264, __pyx_L1_error)
    }
    __pyx_v_variance = ((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_xdata.diminfo[0].strides)) - __pyx_v_peak_min);

    /* "pyquant/cpeaks.pyx":263
 *             # we have only 1 data point, most RT's fall into this width
 *             variance = 0.05
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:             # <<<<<<<<<<<<<<
 *         variance = xdata[peak_index]-peak_min
 *     if variance < min_spacing:
 */
  }

  /* "pyquant/cpeaks.pyx":265
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min
 *     if variance < min_spacing:             # <<<<<<<<<<<<<<
 *         variance = min_spacing
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 */
  __pyx_t_27 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 265, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_27, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 265, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 265, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":266
 *         variance = xdata[peak_index]-peak_min
 *     if variance < min_spacing:
 *         variance = min_spacing             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)
 */
    __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_v_min_spacing); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error)
    __pyx_v_variance = __pyx_t_6;

    /* "pyquant/cpeaks.pyx":265
 *     if variance > xdata[peak_index]-peak_min or variance > peak_max-xdata[peak_index]:
 *         variance = xdata[peak_index]-peak_min
 *     if variance < min_spacing:             # <<<<<<<<<<<<<<
 *         variance = min_spacing
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 */
  }

  /* "pyquant/cpeaks.pyx":267
 *     if variance < min_spacing:
 *         variance = min_spacing
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])             # <<<<<<<<<<<<<<
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000}
 */
  __pyx_t_27 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __pyx_t_26 = __Pyx_PyObject_GetAttrStr(__pyx_t_27, __pyx_n_s_array); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
  __pyx_t_27 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __pyx_t_7 = PyFloat_FromDouble(__pyx_v_peak_loc); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_4 = PyList_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 267, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_27);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_27);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_4, 3, __pyx_t_8);
  __pyx_t_27 = 0;
  __pyx_t_7 = 0;
  __pyx_t_3 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_26))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_26);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_26);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_26, function);
    }
  }
  if (!__pyx_t_8) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_26, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_26, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 267, __pyx_L1_error)
  __pyx_t_35 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_guess.rcbuffer->pybuffer, (PyObject*)__pyx_t_35, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_guess = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_guess.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 267, __pyx_L1_error)
    } else {__pyx_pybuffernd_guess.diminfo[0].strides = __pyx_pybuffernd_guess.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_guess.diminfo[0].shape = __pyx_pybuffernd_guess.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_35 = 0;
  __pyx_v_guess = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":268
 *         variance = min_spacing
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)             # <<<<<<<<<<<<<<
 *     base_opts = {'maxiter': 1000}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 */
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_xdata));
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_ydata));
  __pyx_v_args = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":269
 *     cdef np.ndarray[FLOAT_t] guess = np.array([rel_peak, peak_loc, variance, variance])
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000}             # <<<<<<<<<<<<<<
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)
 */
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_maxiter, __pyx_int_1000) < 0) __PYX_ERR(0, 269, __pyx_L1_error)
  __pyx_v_base_opts = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pyquant/cpeaks.pyx":270
 *     args = (xdata, ydata)
 *     base_opts = {'maxiter': 1000}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]             # <<<<<<<<<<<<<<
 *     routine, opts = routines.pop(0)
 * 
 */
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_SLSQP);
  __Pyx_GIVEREF(__pyx_n_s_SLSQP);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_SLSQP);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_base_opts);
  __pyx_t_26 = PyTuple_New(2); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __Pyx_INCREF(__pyx_n_s_TNC);
  __Pyx_GIVEREF(__pyx_n_s_TNC);
  PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_n_s_TNC);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_26, 1, __pyx_v_base_opts);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_kp_s_L_BFGS_B);
  __Pyx_GIVEREF(__pyx_kp_s_L_BFGS_B);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_s_L_BFGS_B);
  __Pyx_INCREF(__pyx_v_base_opts);
  __Pyx_GIVEREF(__pyx_v_base_opts);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_base_opts);
  __pyx_t_4 = PyList_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 270, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_26);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_t_26);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_5 = 0;
  __pyx_t_26 = 0;
  __pyx_t_3 = 0;
  __pyx_v_routines = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":271
 *     base_opts = {'maxiter': 1000}
 *     routines = [('SLSQP', base_opts), ('TNC', base_opts), ('L-BFGS-B', base_opts)]
 *     routine, opts = routines.pop(0)             # <<<<<<<<<<<<<<
 * 
 *     if debug:
 */
  __pyx_t_4 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
    PyObject* sequence = __pyx_t_4;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 271, __pyx_L1_error)
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_26 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_26 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_26);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_26 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_26);
    #endif
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_36 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_36(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L14_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_26 = __pyx_t_36(__pyx_t_5); if (unlikely(!__pyx_t_26)) goto __pyx_L14_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_26);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_36(__pyx_t_5), 2) < 0) __PYX_ERR(0, 271, __pyx_L1_error)
    __pyx_t_36 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L15_unpacking_done;
    __pyx_L14_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_36 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 271, __pyx_L1_error)
    __pyx_L15_unpacking_done:;
  }
  __pyx_v_routine = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_opts = __pyx_t_26;
  __pyx_t_26 = 0;

  /* "pyquant/cpeaks.pyx":273
 *     routine, opts = routines.pop(0)
 * 
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('guess and bounds', guess, bnds)
 *     try:
 */
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 273, __pyx_L1_error)
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":274
 * 
 *     if debug:
 *         print('guess and bounds', guess, bnds)             # <<<<<<<<<<<<<<
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 */
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 274, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_kp_s_guess_and_bounds);
    __Pyx_GIVEREF(__pyx_kp_s_guess_and_bounds);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_s_guess_and_bounds);
    __Pyx_INCREF(((PyObject *)__pyx_v_guess));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_guess));
    PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_guess));
    __Pyx_INCREF(((PyObject *)__pyx_v_bnds));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_bnds));
    PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_bnds));
    if (__Pyx_PrintOne(0, __pyx_t_4) < 0) __PYX_ERR(0, 274, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pyquant/cpeaks.pyx":273
 *     routine, opts = routines.pop(0)
 * 
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('guess and bounds', guess, bnds)
 *     try:
 */
  }

  /* "pyquant/cpeaks.pyx":275
 *     if debug:
 *         print('guess and bounds', guess, bnds)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 *     except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_12);
    __Pyx_XGOTREF(__pyx_t_11);
    __Pyx_XGOTREF(__pyx_t_10);
    /*try:*/ {

      /* "pyquant/cpeaks.pyx":276
 *         print('guess and bounds', guess, bnds)
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         print 'fitting error'
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_26 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_minimize); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_func); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_guess));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_guess));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_guess));
      __Pyx_INCREF(__pyx_v_args);
      __Pyx_GIVEREF(__pyx_v_args);
      PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_args);
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_bounds, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 276, __pyx_L17_error)
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 276, __pyx_L17_error)
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 276, __pyx_L17_error)
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_jac); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_jac, __pyx_t_5) < 0) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_26, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L17_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_v_results = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;

      /* "pyquant/cpeaks.pyx":275
 *     if debug:
 *         print('guess and bounds', guess, bnds)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 *     except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    goto __pyx_L24_try_end;
    __pyx_L17_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pyquant/cpeaks.pyx":277
 *     try:
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         print 'fitting error'
 *         import traceback
 */
    __pyx_t_2 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_2) {
      __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit2", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_3) < 0) __PYX_ERR(0, 277, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_3);

      /* "pyquant/cpeaks.pyx":278
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 *     except ValueError:
 *         print 'fitting error'             # <<<<<<<<<<<<<<
 *         import traceback
 *         print traceback.format_exc()
 */
      if (__Pyx_PrintOne(0, __pyx_kp_s_fitting_error) < 0) __PYX_ERR(0, 278, __pyx_L19_except_error)

      /* "pyquant/cpeaks.pyx":279
 *     except ValueError:
 *         print 'fitting error'
 *         import traceback             # <<<<<<<<<<<<<<
 *         print traceback.format_exc()
 *         print peak_loc
 */
      __pyx_t_26 = __Pyx_Import(__pyx_n_s_traceback, 0, -1); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 279, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_26);
      __pyx_v_traceback = __pyx_t_26;
      __pyx_t_26 = 0;

      /* "pyquant/cpeaks.pyx":280
 *         print 'fitting error'
 *         import traceback
 *         print traceback.format_exc()             # <<<<<<<<<<<<<<
 *         print peak_loc
 *         print xdata.tolist()
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_traceback, __pyx_n_s_format_exc); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 280, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_7) {
        __pyx_t_26 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 280, __pyx_L19_except_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        __pyx_t_26 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 280, __pyx_L19_except_error)
      }
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 280, __pyx_L19_except_error)
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

      /* "pyquant/cpeaks.pyx":281
 *         import traceback
 *         print traceback.format_exc()
 *         print peak_loc             # <<<<<<<<<<<<<<
 *         print xdata.tolist()
 *         print ydata.tolist()
 */
      __pyx_t_26 = PyFloat_FromDouble(__pyx_v_peak_loc); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 281, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_26);
      if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 281, __pyx_L19_except_error)
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

      /* "pyquant/cpeaks.pyx":282
 *         print traceback.format_exc()
 *         print peak_loc
 *         print xdata.tolist()             # <<<<<<<<<<<<<<
 *         print ydata.tolist()
 *         print bnds
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_xdata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 282, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_7) {
        __pyx_t_26 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 282, __pyx_L19_except_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        __pyx_t_26 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 282, __pyx_L19_except_error)
      }
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 282, __pyx_L19_except_error)
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

      /* "pyquant/cpeaks.pyx":283
 *         print peak_loc
 *         print xdata.tolist()
 *         print ydata.tolist()             # <<<<<<<<<<<<<<
 *         print bnds
 *         results = []
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata), __pyx_n_s_tolist); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 283, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_7) {
        __pyx_t_26 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 283, __pyx_L19_except_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        __pyx_t_26 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 283, __pyx_L19_except_error)
      }
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 283, __pyx_L19_except_error)
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

      /* "pyquant/cpeaks.pyx":284
 *         print xdata.tolist()
 *         print ydata.tolist()
 *         print bnds             # <<<<<<<<<<<<<<
 *         results = []
 *     while routines:# and results[-1].success == False:
 */
      if (__Pyx_PrintOne(0, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 284, __pyx_L19_except_error)

      /* "pyquant/cpeaks.pyx":285
 *         print ydata.tolist()
 *         print bnds
 *         results = []             # <<<<<<<<<<<<<<
 *     while routines:# and results[-1].success == False:
 *         routine, opts = routines.pop(0)
 */
      __pyx_t_26 = PyList_New(0); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 285, __pyx_L19_except_error)
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_XDECREF_SET(__pyx_v_results, ((PyObject*)__pyx_t_26));
      __pyx_t_26 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L18_exception_handled;
    }
    goto __pyx_L19_except_error;
    __pyx_L19_except_error:;

    /* "pyquant/cpeaks.pyx":275
 *     if debug:
 *         print('guess and bounds', guess, bnds)
 *     try:             # <<<<<<<<<<<<<<
 *         results = [optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac)]
 *     except ValueError:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10);
    goto __pyx_L1_error;
    __pyx_L18_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10);
    __pyx_L24_try_end:;
  }

  /* "pyquant/cpeaks.pyx":286
 *         print bnds
 *         results = []
 *     while routines:# and results[-1].success == False:             # <<<<<<<<<<<<<<
 *         routine, opts = routines.pop(0)
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac))
 */
  while (1) {
    __pyx_t_20 = (__pyx_v_routines != Py_None) && (PyList_GET_SIZE(__pyx_v_routines) != 0);
    if (!__pyx_t_20) break;

    /* "pyquant/cpeaks.pyx":287
 *         results = []
 *     while routines:# and results[-1].success == False:
 *         routine, opts = routines.pop(0)             # <<<<<<<<<<<<<<
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac))
 *     # cdef int n = len(xdata)
 */
    __pyx_t_3 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __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_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 287, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_26 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_36 = Py_TYPE(__pyx_t_26)->tp_iternext;
      index = 0; __pyx_t_5 = __pyx_t_36(__pyx_t_26); if (unlikely(!__pyx_t_5)) goto __pyx_L29_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      index = 1; __pyx_t_4 = __pyx_t_36(__pyx_t_26); if (unlikely(!__pyx_t_4)) goto __pyx_L29_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_36(__pyx_t_26), 2) < 0) __PYX_ERR(0, 287, __pyx_L1_error)
      __pyx_t_36 = NULL;
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      goto __pyx_L30_unpacking_done;
      __pyx_L29_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      __pyx_t_36 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 287, __pyx_L1_error)
      __pyx_L30_unpacking_done:;
    }
    __Pyx_DECREF_SET(__pyx_v_routine, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_opts, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pyquant/cpeaks.pyx":288
 *     while routines:# and results[-1].success == False:
 *         routine, opts = routines.pop(0)
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac))             # <<<<<<<<<<<<<<
 *     # cdef int n = len(xdata)
 *     cdef float lowest = -1
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_minimize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_func); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_guess));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_guess));
    PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_guess));
    __Pyx_INCREF(__pyx_v_args);
    __Pyx_GIVEREF(__pyx_v_args);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_args);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_bounds, ((PyObject *)__pyx_v_bnds)) < 0) __PYX_ERR(0, 288, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 288, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 288, __pyx_L1_error)
    __pyx_t_26 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_jac); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_26);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_jac, __pyx_t_26) < 0) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
    __pyx_t_26 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_26);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_37 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_26); if (unlikely(__pyx_t_37 == -1)) __PYX_ERR(0, 288, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
  }

  /* "pyquant/cpeaks.pyx":290
 *         results.append(optimize.minimize(bigauss_func, guess, args, bounds=bnds, method=routine, options=opts, jac=bigauss_jac))
 *     # cdef int n = len(xdata)
 *     cdef float lowest = -1             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t] best
 *     if debug:
 */
  __pyx_v_lowest = -1.0;

  /* "pyquant/cpeaks.pyx":292
 *     cdef float lowest = -1
 *     cdef np.ndarray[FLOAT_t] best
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('fitting results', results)
 *     best_fit = results[0]
 */
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 292, __pyx_L1_error)
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":293
 *     cdef np.ndarray[FLOAT_t] best
 *     if debug:
 *         print('fitting results', results)             # <<<<<<<<<<<<<<
 *     best_fit = results[0]
 *     for i in results:
 */
    __pyx_t_26 = PyTuple_New(2); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_26);
    __Pyx_INCREF(__pyx_kp_s_fitting_results);
    __Pyx_GIVEREF(__pyx_kp_s_fitting_results);
    PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_kp_s_fitting_results);
    __Pyx_INCREF(__pyx_v_results);
    __Pyx_GIVEREF(__pyx_v_results);
    PyTuple_SET_ITEM(__pyx_t_26, 1, __pyx_v_results);
    if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

    /* "pyquant/cpeaks.pyx":292
 *     cdef float lowest = -1
 *     cdef np.ndarray[FLOAT_t] best
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('fitting results', results)
 *     best_fit = results[0]
 */
  }

  /* "pyquant/cpeaks.pyx":294
 *     if debug:
 *         print('fitting results', results)
 *     best_fit = results[0]             # <<<<<<<<<<<<<<
 *     for i in results:
 *         if within_bounds(i.x, bnds):
 */
  __pyx_t_26 = __Pyx_GetItemInt_List(__pyx_v_results, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __pyx_v_best_fit = __pyx_t_26;
  __pyx_t_26 = 0;

  /* "pyquant/cpeaks.pyx":295
 *         print('fitting results', results)
 *     best_fit = results[0]
 *     for i in results:             # <<<<<<<<<<<<<<
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 */
  __pyx_t_26 = __pyx_v_results; __Pyx_INCREF(__pyx_t_26); __pyx_t_15 = 0;
  for (;;) {
    if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_26)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_26, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 295, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_26, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":296
 *     best_fit = results[0]
 *     for i in results:
 *         if within_bounds(i.x, bnds):             # <<<<<<<<<<<<<<
 *             if lowest == -1 or i.fun < lowest:
 *                 best_fit = i
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_i, __pyx_n_s_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 296, __pyx_L1_error)
    __pyx_t_20 = (__pyx_f_7pyquant_6cpeaks_within_bounds(((PyArrayObject *)__pyx_t_3), ((PyArrayObject *)__pyx_v_bnds)) != 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_20) {

      /* "pyquant/cpeaks.pyx":297
 *     for i in results:
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:             # <<<<<<<<<<<<<<
 *                 best_fit = i
 *     best_fit.x[0]*=mval
 */
      __pyx_t_32 = ((__pyx_v_lowest == -1.0) != 0);
      if (!__pyx_t_32) {
      } else {
        __pyx_t_20 = __pyx_t_32;
        goto __pyx_L36_bool_binop_done;
      }
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_i, __pyx_n_s_fun); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyFloat_FromDouble(__pyx_v_lowest); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_32 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_32 < 0)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_20 = __pyx_t_32;
      __pyx_L36_bool_binop_done:;
      if (__pyx_t_20) {

        /* "pyquant/cpeaks.pyx":298
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 *                 best_fit = i             # <<<<<<<<<<<<<<
 *     best_fit.x[0]*=mval
 *     if debug:
 */
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_DECREF_SET(__pyx_v_best_fit, __pyx_v_i);

        /* "pyquant/cpeaks.pyx":297
 *     for i in results:
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:             # <<<<<<<<<<<<<<
 *                 best_fit = i
 *     best_fit.x[0]*=mval
 */
      }

      /* "pyquant/cpeaks.pyx":296
 *     best_fit = results[0]
 *     for i in results:
 *         if within_bounds(i.x, bnds):             # <<<<<<<<<<<<<<
 *             if lowest == -1 or i.fun < lowest:
 *                 best_fit = i
 */
    }

    /* "pyquant/cpeaks.pyx":295
 *         print('fitting results', results)
 *     best_fit = results[0]
 *     for i in results:             # <<<<<<<<<<<<<<
 *         if within_bounds(i.x, bnds):
 *             if lowest == -1 or i.fun < lowest:
 */
  }
  __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

  /* "pyquant/cpeaks.pyx":299
 *             if lowest == -1 or i.fun < lowest:
 *                 best_fit = i
 *     best_fit.x[0]*=mval             # <<<<<<<<<<<<<<
 *     if debug:
 *         print('best fit', best_fit)
 */
  __pyx_t_26 = __Pyx_PyObject_GetAttrStr(__pyx_v_best_fit, __pyx_n_s_x); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __pyx_t_15 = 0;
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_26, __pyx_t_15, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_mval); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(__Pyx_SetItemInt(__pyx_t_26, __pyx_t_15, __pyx_t_3, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1) < 0)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

  /* "pyquant/cpeaks.pyx":300
 *                 best_fit = i
 *     best_fit.x[0]*=mval
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('best fit', best_fit)
 *     # cdef int k = len(best.x)
 */
  __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 300, __pyx_L1_error)
  if (__pyx_t_20) {

    /* "pyquant/cpeaks.pyx":301
 *     best_fit.x[0]*=mval
 *     if debug:
 *         print('best fit', best_fit)             # <<<<<<<<<<<<<<
 *     # cdef int k = len(best.x)
 *     # cdef float bic = n*np.log(best.fun/n)+k+np.log(n)
 */
    __pyx_t_26 = PyTuple_New(2); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_26);
    __Pyx_INCREF(__pyx_kp_s_best_fit);
    __Pyx_GIVEREF(__pyx_kp_s_best_fit);
    PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_kp_s_best_fit);
    __Pyx_INCREF(__pyx_v_best_fit);
    __Pyx_GIVEREF(__pyx_v_best_fit);
    PyTuple_SET_ITEM(__pyx_t_26, 1, __pyx_v_best_fit);
    if (__Pyx_PrintOne(0, __pyx_t_26) < 0) __PYX_ERR(0, 301, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;

    /* "pyquant/cpeaks.pyx":300
 *                 best_fit = i
 *     best_fit.x[0]*=mval
 *     if debug:             # <<<<<<<<<<<<<<
 *         print('best fit', best_fit)
 *     # cdef int k = len(best.x)
 */
  }

  /* "pyquant/cpeaks.pyx":305
 *     # cdef float bic = n*np.log(best.fun/n)+k+np.log(n)
 *     # best.bic = bic
 *     return best_fit.x, best_fit.fun             # <<<<<<<<<<<<<<
 * 
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_26 = __Pyx_PyObject_GetAttrStr(__pyx_v_best_fit, __pyx_n_s_x); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_26);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_best_fit, __pyx_n_s_fun); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_26);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_26);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __pyx_t_26 = 0;
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":215
 *     return best
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak, mval
 */

  /* 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_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_26);
  __Pyx_XDECREF(__pyx_t_27);
  { 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_bnds.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_conv_y.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bnds.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_conv_y.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_guess.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_conv_y);
  __Pyx_XDECREF((PyObject *)__pyx_v_bnds);
  __Pyx_XDECREF(__pyx_v_min_spacing);
  __Pyx_XDECREF(__pyx_v_lb);
  __Pyx_XDECREF(__pyx_v_rb);
  __Pyx_XDECREF((PyObject *)__pyx_v_guess);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_base_opts);
  __Pyx_XDECREF(__pyx_v_routines);
  __Pyx_XDECREF(__pyx_v_routine);
  __Pyx_XDECREF(__pyx_v_opts);
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XDECREF(__pyx_v_traceback);
  __Pyx_XDECREF(__pyx_v_best_fit);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF((PyObject *)__pyx_v_xdata);
  __Pyx_XDECREF((PyObject *)__pyx_v_ydata);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_15fixedMeanFit2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_15fixedMeanFit2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  int __pyx_v_peak_index;
  PyObject *__pyx_v_debug = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fixedMeanFit2 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_ydata,&__pyx_n_s_peak_index,&__pyx_n_s_debug,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pyquant/cpeaks.pyx":216
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,
 *                                        int peak_index=1, debug=False):             # <<<<<<<<<<<<<<
 *     cdef float rel_peak, mval
 *     cdef float peak_loc = xdata[peak_index]
 */
    values[3] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("fixedMeanFit2", 0, 2, 4, 1); __PYX_ERR(0, 215, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_peak_index);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_debug);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fixedMeanFit2") < 0)) __PYX_ERR(0, 215, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_ydata = ((PyArrayObject *)values[1]);
    if (values[2]) {
      __pyx_v_peak_index = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_peak_index == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 216, __pyx_L3_error)
    } else {
      __pyx_v_peak_index = ((int)1);
    }
    __pyx_v_debug = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fixedMeanFit2", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 215, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 215, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 215, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_14fixedMeanFit2(__pyx_self, __pyx_v_xdata, __pyx_v_ydata, __pyx_v_peak_index, __pyx_v_debug);

  /* "pyquant/cpeaks.pyx":215
 *     return best
 * 
 * cpdef tuple fixedMeanFit2(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata,             # <<<<<<<<<<<<<<
 *                                        int peak_index=1, debug=False):
 *     cdef float rel_peak, mval
 */

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_14fixedMeanFit2(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, int __pyx_v_peak_index, PyObject *__pyx_v_debug) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7pyquant_6cpeaks_fixedMeanFit2 __pyx_t_2;
  __Pyx_RefNannySetupContext("fixedMeanFit2", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.peak_index = __pyx_v_peak_index;
  __pyx_t_2.debug = __pyx_v_debug;
  __pyx_t_1 = __pyx_f_7pyquant_6cpeaks_fixedMeanFit2(__pyx_v_xdata, __pyx_v_ydata, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.fixedMeanFit2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":307
 *     return best_fit.x, best_fit.fun
 * 
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):             # <<<<<<<<<<<<<<
 *     args[::1] += 0.1
 *     args[::2] += 0.1
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_17basin_stepper(PyObject *__pyx_self, PyObject *__pyx_v_args); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_basin_stepper(PyArrayObject *__pyx_v_args, CYTHON_UNUSED int __pyx_skip_dispatch) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_args;
  __Pyx_Buffer __pyx_pybuffer_args;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("basin_stepper", 0);
  __pyx_pybuffer_args.pybuffer.buf = NULL;
  __pyx_pybuffer_args.refcount = 0;
  __pyx_pybuffernd_args.data = NULL;
  __pyx_pybuffernd_args.rcbuffer = &__pyx_pybuffer_args;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_args.rcbuffer->pybuffer, (PyObject*)__pyx_v_args, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 307, __pyx_L1_error)
  }
  __pyx_pybuffernd_args.diminfo[0].strides = __pyx_pybuffernd_args.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_args.diminfo[0].shape = __pyx_pybuffernd_args.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":308
 * 
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):
 *     args[::1] += 0.1             # <<<<<<<<<<<<<<
 *     args[::2] += 0.1
 *     args[::3] += 0.05
 */
  __Pyx_INCREF(__pyx_slice__13);
  __pyx_t_1 = __pyx_slice__13;
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyFloat_AddObjC(__pyx_t_2, __pyx_float_0_1, 0.1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_args), __pyx_t_1, __pyx_t_3) < 0)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":309
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):
 *     args[::1] += 0.1
 *     args[::2] += 0.1             # <<<<<<<<<<<<<<
 *     args[::3] += 0.05
 *     args[::4] += 0.05
 */
  __Pyx_INCREF(__pyx_slice__14);
  __pyx_t_1 = __pyx_slice__14;
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyFloat_AddObjC(__pyx_t_3, __pyx_float_0_1, 0.1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_args), __pyx_t_1, __pyx_t_2) < 0)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":310
 *     args[::1] += 0.1
 *     args[::2] += 0.1
 *     args[::3] += 0.05             # <<<<<<<<<<<<<<
 *     args[::4] += 0.05
 *     return args
 */
  __Pyx_INCREF(__pyx_slice__15);
  __pyx_t_1 = __pyx_slice__15;
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyFloat_AddObjC(__pyx_t_2, __pyx_float_0_05, 0.05, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_args), __pyx_t_1, __pyx_t_3) < 0)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":311
 *     args[::2] += 0.1
 *     args[::3] += 0.05
 *     args[::4] += 0.05             # <<<<<<<<<<<<<<
 *     return args
 * 
 */
  __Pyx_INCREF(__pyx_slice__16);
  __pyx_t_1 = __pyx_slice__16;
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyFloat_AddObjC(__pyx_t_3, __pyx_float_0_05, 0.05, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_args), __pyx_t_1, __pyx_t_2) < 0)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":312
 *     args[::3] += 0.05
 *     args[::4] += 0.05
 *     return args             # <<<<<<<<<<<<<<
 * 
 * @cython.boundscheck(False)
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_args));
  __pyx_r = ((PyObject *)__pyx_v_args);
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":307
 *     return best_fit.x, best_fit.fun
 * 
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):             # <<<<<<<<<<<<<<
 *     args[::1] += 0.1
 *     args[::2] += 0.1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_args.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.basin_stepper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_args.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_17basin_stepper(PyObject *__pyx_self, PyObject *__pyx_v_args); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_17basin_stepper(PyObject *__pyx_self, PyObject *__pyx_v_args) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("basin_stepper (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_args), __pyx_ptype_5numpy_ndarray, 1, "args", 0))) __PYX_ERR(0, 307, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_16basin_stepper(__pyx_self, ((PyArrayObject *)__pyx_v_args));

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_16basin_stepper(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_args) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_args;
  __Pyx_Buffer __pyx_pybuffer_args;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("basin_stepper", 0);
  __pyx_pybuffer_args.pybuffer.buf = NULL;
  __pyx_pybuffer_args.refcount = 0;
  __pyx_pybuffernd_args.data = NULL;
  __pyx_pybuffernd_args.rcbuffer = &__pyx_pybuffer_args;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_args.rcbuffer->pybuffer, (PyObject*)__pyx_v_args, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 307, __pyx_L1_error)
  }
  __pyx_pybuffernd_args.diminfo[0].strides = __pyx_pybuffernd_args.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_args.diminfo[0].shape = __pyx_pybuffernd_args.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_7pyquant_6cpeaks_basin_stepper(__pyx_v_args, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_args.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.basin_stepper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_args.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":315
 * 
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,             # <<<<<<<<<<<<<<
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_19findAllPeaks(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_findAllPeaks(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata_original, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_findAllPeaks *__pyx_optional_args) {

  /* "pyquant/cpeaks.pyx":316
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,             # <<<<<<<<<<<<<<
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 *                          peak_width_end=4):
 */
  PyObject *__pyx_v_filter = ((PyObject *)Py_False);
  PyObject *__pyx_v_bigauss_fit = ((PyObject *)Py_False);
  PyObject *__pyx_v_rt_peak = ((PyObject *)__pyx_float_0_0);
  int __pyx_v_max_peaks = ((int)4);

  /* "pyquant/cpeaks.pyx":317
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,             # <<<<<<<<<<<<<<
 *                          peak_width_end=4):
 *     cdef object fit_func, jacobian
 */
  PyObject *__pyx_v_debug = ((PyObject *)Py_False);
  PyObject *__pyx_v_peak_width_start = ((PyObject *)__pyx_int_2);
  PyObject *__pyx_v_snr = ((PyObject *)__pyx_int_0);
  PyObject *__pyx_v_amplitude_filter = ((PyObject *)__pyx_int_0);
  PyObject *__pyx_v_peak_width_end = ((PyObject *)__pyx_int_4);
  PyObject *__pyx_v_fit_func = 0;
  PyObject *__pyx_v_jacobian = 0;
  PyArrayObject *__pyx_v_row_peaks = 0;
  PyArrayObject *__pyx_v_smaller_peaks = 0;
  PyArrayObject *__pyx_v_larger_peaks = 0;
  PyArrayObject *__pyx_v_minima_array = 0;
  PyObject *__pyx_v_minima = 0;
  CYTHON_UNUSED PyObject *__pyx_v_fit_accuracy = 0;
  PyObject *__pyx_v_smaller_minima = 0;
  PyObject *__pyx_v_larger_minima = 0;
  PyObject *__pyx_v_guess = 0;
  PyObject *__pyx_v_bnds = 0;
  PyObject *__pyx_v_peaks_found = 0;
  PyObject *__pyx_v_final_peaks = 0;
  PyObject *__pyx_v_peak_info = 0;
  int __pyx_v_peak_width;
  int __pyx_v_last_peak;
  int __pyx_v_next_peak;
  int __pyx_v_left;
  int __pyx_v_right;
  int __pyx_v_i;
  int __pyx_v_minima_index;
  int __pyx_v_left_stop;
  int __pyx_v_right_stop;
  float __pyx_v_rel_peak;
  float __pyx_v_average;
  float __pyx_v_variance;
  float __pyx_v_best_rss;
  float __pyx_v_rt_peak_val;
  float __pyx_v_minima_value;
  PyArrayObject *__pyx_v_peak_values = 0;
  PyArrayObject *__pyx_v_peak_indices = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  PyArrayObject *__pyx_v_ydata_peaks = 0;
  PyArrayObject *__pyx_v_best_fit = 0;
  PyObject *__pyx_v_mapper = NULL;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_opts = 0;
  PyObject *__pyx_v_routines = 0;
  PyObject *__pyx_v_results = 0;
  PyObject *__pyx_v_routine = 0;
  PyObject *__pyx_v_res = 0;
  PyObject *__pyx_v_best_res = 0;
  float __pyx_v_bic;
  float __pyx_v_n;
  float __pyx_v_k;
  float __pyx_v_lowest_bic;
  PyObject *__pyx_v_min_spacing = NULL;
  PyObject *__pyx_v_peak_range = NULL;
  PyObject *__pyx_v_initial_bounds = NULL;
  PyObject *__pyx_v_skip_peaks = NULL;
  PyObject *__pyx_v_fitted_peaks = NULL;
  PyObject *__pyx_v_peak_num = NULL;
  PyObject *__pyx_v_peak_index = NULL;
  PyObject *__pyx_v_step_size = NULL;
  PyObject *__pyx_v_index = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_mean = NULL;
  PyObject *__pyx_v_lstd = NULL;
  PyObject *__pyx_v_rstd = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_best_fit;
  __Pyx_Buffer __pyx_pybuffer_best_fit;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_larger_peaks;
  __Pyx_Buffer __pyx_pybuffer_larger_peaks;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_minima_array;
  __Pyx_Buffer __pyx_pybuffer_minima_array;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_peak_indices;
  __Pyx_Buffer __pyx_pybuffer_peak_indices;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_peak_values;
  __Pyx_Buffer __pyx_pybuffer_peak_values;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_row_peaks;
  __Pyx_Buffer __pyx_pybuffer_row_peaks;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_smaller_peaks;
  __Pyx_Buffer __pyx_pybuffer_smaller_peaks;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata_original;
  __Pyx_Buffer __pyx_pybuffer_ydata_original;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata_peaks;
  __Pyx_Buffer __pyx_pybuffer_ydata_peaks;
  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;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  float __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  int __pyx_t_19;
  int __pyx_t_20;
  long __pyx_t_21;
  long __pyx_t_22;
  int __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  PyObject *(*__pyx_t_28)(PyObject *);
  PyArrayObject *__pyx_t_29 = NULL;
  Py_ssize_t __pyx_t_30;
  PyObject *(*__pyx_t_31)(PyObject *);
  Py_ssize_t __pyx_t_32;
  Py_ssize_t __pyx_t_33;
  PyObject *__pyx_t_34 = NULL;
  Py_ssize_t __pyx_t_35;
  Py_ssize_t __pyx_t_36;
  Py_ssize_t __pyx_t_37;
  Py_ssize_t __pyx_t_38;
  Py_ssize_t __pyx_t_39;
  Py_ssize_t __pyx_t_40;
  Py_ssize_t __pyx_t_41;
  Py_ssize_t __pyx_t_42;
  Py_ssize_t __pyx_t_43;
  Py_ssize_t __pyx_t_44;
  Py_ssize_t __pyx_t_45;
  Py_ssize_t __pyx_t_46;
  Py_ssize_t __pyx_t_47;
  Py_ssize_t __pyx_t_48;
  Py_ssize_t __pyx_t_49;
  PyObject *__pyx_t_50 = NULL;
  __Pyx_RefNannySetupContext("findAllPeaks", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 1) {
      __pyx_v_filter = __pyx_optional_args->filter;
      if (__pyx_optional_args->__pyx_n > 2) {
        __pyx_v_bigauss_fit = __pyx_optional_args->bigauss_fit;
        if (__pyx_optional_args->__pyx_n > 3) {
          __pyx_v_rt_peak = __pyx_optional_args->rt_peak;
          if (__pyx_optional_args->__pyx_n > 5) {
            __pyx_v_max_peaks = __pyx_optional_args->max_peaks;
            if (__pyx_optional_args->__pyx_n > 6) {
              __pyx_v_debug = __pyx_optional_args->debug;
              if (__pyx_optional_args->__pyx_n > 7) {
                __pyx_v_peak_width_start = __pyx_optional_args->peak_width_start;
                if (__pyx_optional_args->__pyx_n > 8) {
                  __pyx_v_snr = __pyx_optional_args->snr;
                  if (__pyx_optional_args->__pyx_n > 9) {
                    __pyx_v_amplitude_filter = __pyx_optional_args->amplitude_filter;
                    if (__pyx_optional_args->__pyx_n > 10) {
                      __pyx_v_peak_width_end = __pyx_optional_args->peak_width_end;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  __Pyx_INCREF(__pyx_v_peak_width_start);
  __Pyx_INCREF(__pyx_v_amplitude_filter);
  __pyx_pybuffer_row_peaks.pybuffer.buf = NULL;
  __pyx_pybuffer_row_peaks.refcount = 0;
  __pyx_pybuffernd_row_peaks.data = NULL;
  __pyx_pybuffernd_row_peaks.rcbuffer = &__pyx_pybuffer_row_peaks;
  __pyx_pybuffer_smaller_peaks.pybuffer.buf = NULL;
  __pyx_pybuffer_smaller_peaks.refcount = 0;
  __pyx_pybuffernd_smaller_peaks.data = NULL;
  __pyx_pybuffernd_smaller_peaks.rcbuffer = &__pyx_pybuffer_smaller_peaks;
  __pyx_pybuffer_larger_peaks.pybuffer.buf = NULL;
  __pyx_pybuffer_larger_peaks.refcount = 0;
  __pyx_pybuffernd_larger_peaks.data = NULL;
  __pyx_pybuffernd_larger_peaks.rcbuffer = &__pyx_pybuffer_larger_peaks;
  __pyx_pybuffer_minima_array.pybuffer.buf = NULL;
  __pyx_pybuffer_minima_array.refcount = 0;
  __pyx_pybuffernd_minima_array.data = NULL;
  __pyx_pybuffernd_minima_array.rcbuffer = &__pyx_pybuffer_minima_array;
  __pyx_pybuffer_peak_values.pybuffer.buf = NULL;
  __pyx_pybuffer_peak_values.refcount = 0;
  __pyx_pybuffernd_peak_values.data = NULL;
  __pyx_pybuffernd_peak_values.rcbuffer = &__pyx_pybuffer_peak_values;
  __pyx_pybuffer_peak_indices.pybuffer.buf = NULL;
  __pyx_pybuffer_peak_indices.refcount = 0;
  __pyx_pybuffernd_peak_indices.data = NULL;
  __pyx_pybuffernd_peak_indices.rcbuffer = &__pyx_pybuffer_peak_indices;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  __pyx_pybuffer_ydata_peaks.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata_peaks.refcount = 0;
  __pyx_pybuffernd_ydata_peaks.data = NULL;
  __pyx_pybuffernd_ydata_peaks.rcbuffer = &__pyx_pybuffer_ydata_peaks;
  __pyx_pybuffer_best_fit.pybuffer.buf = NULL;
  __pyx_pybuffer_best_fit.refcount = 0;
  __pyx_pybuffernd_best_fit.data = NULL;
  __pyx_pybuffernd_best_fit.rcbuffer = &__pyx_pybuffer_best_fit;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata_original.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata_original.refcount = 0;
  __pyx_pybuffernd_ydata_original.data = NULL;
  __pyx_pybuffernd_ydata_original.rcbuffer = &__pyx_pybuffer_ydata_original;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 315, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_original, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 315, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata_original.diminfo[0].strides = __pyx_pybuffernd_ydata_original.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_original.diminfo[0].shape = __pyx_pybuffernd_ydata_original.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":328
 *     cdef np.ndarray[FLOAT_t, ndim=1] peak_values, peak_indices, ydata, ydata_peaks, best_fit
 * 
 *     amplitude_filter /= ydata_original.max()             # <<<<<<<<<<<<<<
 *     ydata = ydata_original/ydata_original.max()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata_original), __pyx_n_s_max); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(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, 328, __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, 328, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyNumber_InPlaceDivide(__pyx_v_amplitude_filter, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_amplitude_filter, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":329
 * 
 *     amplitude_filter /= ydata_original.max()
 *     ydata = ydata_original/ydata_original.max()             # <<<<<<<<<<<<<<
 * 
 *     ydata_peaks = np.copy(ydata)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata_original), __pyx_n_s_max); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 329, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 329, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_ydata_original), __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __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, 329, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 329, __pyx_L1_error)
  }
  __pyx_t_4 = 0;
  __pyx_v_ydata = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":331
 *     ydata = ydata_original/ydata_original.max()
 * 
 *     ydata_peaks = np.copy(ydata)             # <<<<<<<<<<<<<<
 *     if snr != 0:
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 331, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 331, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_ydata)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 331, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 331, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); __pyx_t_2 = NULL;
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
    PyTuple_SET_ITEM(__pyx_t_9, 0+1, ((PyObject *)__pyx_v_ydata));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 331, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 331, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_peaks, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
      }
    }
    __pyx_pybuffernd_ydata_peaks.diminfo[0].strides = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_peaks.diminfo[0].shape = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 331, __pyx_L1_error)
  }
  __pyx_t_4 = 0;
  __pyx_v_ydata_peaks = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":332
 * 
 *     ydata_peaks = np.copy(ydata)
 *     if snr != 0:             # <<<<<<<<<<<<<<
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 *     if amplitude_filter != 0:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_snr, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error)
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 332, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_10) {

    /* "pyquant/cpeaks.pyx":333
 *     ydata_peaks = np.copy(ydata)
 *     if snr != 0:
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0             # <<<<<<<<<<<<<<
 *     if amplitude_filter != 0:
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_std); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, ((PyObject *)__pyx_v_ydata_peaks)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, ((PyObject *)__pyx_v_ydata_peaks));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_9, __pyx_v_snr, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_1, __pyx_int_0) < 0)) __PYX_ERR(0, 333, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":332
 * 
 *     ydata_peaks = np.copy(ydata)
 *     if snr != 0:             # <<<<<<<<<<<<<<
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 *     if amplitude_filter != 0:
 */
  }

  /* "pyquant/cpeaks.pyx":334
 *     if snr != 0:
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 *     if amplitude_filter != 0:             # <<<<<<<<<<<<<<
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_amplitude_filter, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error)
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_10) {

    /* "pyquant/cpeaks.pyx":335
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 *     if amplitude_filter != 0:
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0             # <<<<<<<<<<<<<<
 *     if filter:
 *         if len(ydata) >= 5:
 */
    __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata_peaks), __pyx_v_amplitude_filter, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 335, __pyx_L1_error)
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_1, __pyx_int_0) < 0)) __PYX_ERR(0, 335, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":334
 *     if snr != 0:
 *         ydata_peaks[ydata_peaks/np.std(ydata_peaks)<snr] = 0
 *     if amplitude_filter != 0:             # <<<<<<<<<<<<<<
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:
 */
  }

  /* "pyquant/cpeaks.pyx":336
 *     if amplitude_filter != 0:
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:             # <<<<<<<<<<<<<<
 *         if len(ydata) >= 5:
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 */
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_filter); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 336, __pyx_L1_error)
  if (__pyx_t_10) {

    /* "pyquant/cpeaks.pyx":337
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:
 *         if len(ydata) >= 5:             # <<<<<<<<<<<<<<
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 *             ydata_peaks[ydata_peaks<0] = 0
 */
    __pyx_t_11 = PyObject_Length(((PyObject *)__pyx_v_ydata)); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 337, __pyx_L1_error)
    __pyx_t_10 = ((__pyx_t_11 >= 5) != 0);
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":338
 *     if filter:
 *         if len(ydata) >= 5:
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')             # <<<<<<<<<<<<<<
 *             ydata_peaks[ydata_peaks<0] = 0
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_convolve); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_kaiser); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
      PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_v_ydata_peaks));
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_mode, __pyx_n_s_same) < 0) __PYX_ERR(0, 338, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 338, __pyx_L1_error)
      __pyx_t_4 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
        __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_5 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_peaks, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_ydata_peaks.diminfo[0].strides = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_peaks.diminfo[0].shape = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 338, __pyx_L1_error)
      }
      __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_ydata_peaks, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":339
 *         if len(ydata) >= 5:
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 *             ydata_peaks[ydata_peaks<0] = 0             # <<<<<<<<<<<<<<
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 *     mapper = interp1d(xdata, ydata_peaks)
 */
      __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata_peaks), __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 339, __pyx_L1_error)
      if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_3, __pyx_int_0) < 0)) __PYX_ERR(0, 339, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":337
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:
 *         if len(ydata) >= 5:             # <<<<<<<<<<<<<<
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 *             ydata_peaks[ydata_peaks<0] = 0
 */
    }

    /* "pyquant/cpeaks.pyx":336
 *     if amplitude_filter != 0:
 *         ydata_peaks[ydata_peaks<amplitude_filter] = 0
 *     if filter:             # <<<<<<<<<<<<<<
 *         if len(ydata) >= 5:
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 */
  }

  /* "pyquant/cpeaks.pyx":340
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')
 *             ydata_peaks[ydata_peaks<0] = 0
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0             # <<<<<<<<<<<<<<
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_isnan); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_9, ((PyObject *)__pyx_v_ydata_peaks)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 340, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
    PyTuple_SET_ITEM(__pyx_t_1, 0+1, ((PyObject *)__pyx_v_ydata_peaks));
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_3, __pyx_int_0) < 0)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":341
 *             ydata_peaks[ydata_peaks<0] = 0
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 *     mapper = interp1d(xdata, ydata_peaks)             # <<<<<<<<<<<<<<
 *     if rt_peak != 0:
 *         try:
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_interp1d); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
      __pyx_t_11 = 1;
    }
  }
  __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__pyx_t_1) {
    __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, ((PyObject *)__pyx_v_xdata));
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
  PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, ((PyObject *)__pyx_v_ydata_peaks));
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_mapper = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":342
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:             # <<<<<<<<<<<<<<
 *         try:
 *             rt_peak_val = mapper(rt_peak)
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_rt_peak, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 342, __pyx_L1_error)
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 342, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_10) {

    /* "pyquant/cpeaks.pyx":343
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:
 *         try:             # <<<<<<<<<<<<<<
 *             rt_peak_val = mapper(rt_peak)
 *         except ValueError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_6);
      /*try:*/ {

        /* "pyquant/cpeaks.pyx":344
 *     if rt_peak != 0:
 *         try:
 *             rt_peak_val = mapper(rt_peak)             # <<<<<<<<<<<<<<
 *         except ValueError:
 *             rt_peak_val = ydata_peaks[find_nearest_index(xdata, rt_peak)]
 */
        __Pyx_INCREF(__pyx_v_mapper);
        __pyx_t_9 = __pyx_v_mapper; __pyx_t_2 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && 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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_rt_peak); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 344, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_INCREF(__pyx_v_rt_peak);
          __Pyx_GIVEREF(__pyx_v_rt_peak);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_rt_peak);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 344, __pyx_L8_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_rt_peak_val = __pyx_t_12;

        /* "pyquant/cpeaks.pyx":343
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:
 *         try:             # <<<<<<<<<<<<<<
 *             rt_peak_val = mapper(rt_peak)
 *         except ValueError:
 */
      }
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L15_try_end;
      __pyx_L8_error:;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":345
 *         try:
 *             rt_peak_val = mapper(rt_peak)
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             rt_peak_val = ydata_peaks[find_nearest_index(xdata, rt_peak)]
 *         ydata_peaks = np.where(ydata_peaks > rt_peak_val*0.9, ydata_peaks, 0)
 */
      __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
      if (__pyx_t_5) {
        __Pyx_AddTraceback("pyquant.cpeaks.findAllPeaks", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_9, &__pyx_t_1) < 0) __PYX_ERR(0, 345, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_1);

        /* "pyquant/cpeaks.pyx":346
 *             rt_peak_val = mapper(rt_peak)
 *         except ValueError:
 *             rt_peak_val = ydata_peaks[find_nearest_index(xdata, rt_peak)]             # <<<<<<<<<<<<<<
 *         ydata_peaks = np.where(ydata_peaks > rt_peak_val*0.9, ydata_peaks, 0)
 * 
 */
        __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 346, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_14 = NULL;
        __pyx_t_11 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_13, function);
            __pyx_t_11 = 1;
          }
        }
        __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 346, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
        PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, ((PyObject *)__pyx_v_xdata));
        __Pyx_INCREF(__pyx_v_rt_peak);
        __Pyx_GIVEREF(__pyx_v_rt_peak);
        PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_v_rt_peak);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = PyObject_GetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 346, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_13); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 346, __pyx_L10_except_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_v_rt_peak_val = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L9_exception_handled;
      }
      goto __pyx_L10_except_error;
      __pyx_L10_except_error:;

      /* "pyquant/cpeaks.pyx":343
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:
 *         try:             # <<<<<<<<<<<<<<
 *             rt_peak_val = mapper(rt_peak)
 *         except ValueError:
 */
      __Pyx_PyThreadState_assign
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_7, __pyx_t_6);
      goto __pyx_L1_error;
      __pyx_L9_exception_handled:;
      __Pyx_PyThreadState_assign
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_7, __pyx_t_6);
      __pyx_L15_try_end:;
    }

    /* "pyquant/cpeaks.pyx":347
 *         except ValueError:
 *             rt_peak_val = ydata_peaks[find_nearest_index(xdata, rt_peak)]
 *         ydata_peaks = np.where(ydata_peaks > rt_peak_val*0.9, ydata_peaks, 0)             # <<<<<<<<<<<<<<
 * 
 *     ydata_peaks /= ydata_peaks.max()
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_where); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyFloat_FromDouble((__pyx_v_rt_peak_val * 0.9)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_13 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_9, Py_GT); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    __pyx_t_2 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_9) {
      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9); __pyx_t_9 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_t_13);
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, ((PyObject *)__pyx_v_ydata_peaks));
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_11, __pyx_int_0);
    __pyx_t_13 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 347, __pyx_L1_error)
    __pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
      __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_5 < 0)) {
        PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_peaks, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        }
      }
      __pyx_pybuffernd_ydata_peaks.diminfo[0].strides = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_peaks.diminfo[0].shape = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 347, __pyx_L1_error)
    }
    __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_ydata_peaks, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":342
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 *     mapper = interp1d(xdata, ydata_peaks)
 *     if rt_peak != 0:             # <<<<<<<<<<<<<<
 *         try:
 *             rt_peak_val = mapper(rt_peak)
 */
  }

  /* "pyquant/cpeaks.pyx":349
 *         ydata_peaks = np.where(ydata_peaks > rt_peak_val*0.9, ydata_peaks, 0)
 * 
 *     ydata_peaks /= ydata_peaks.max()             # <<<<<<<<<<<<<<
 * 
 *     peaks_found = {}
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata_peaks), __pyx_n_s_max); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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, 349, __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, 349, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_ydata_peaks), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 349, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
    __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_5 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_peaks, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
      }
    }
    __pyx_pybuffernd_ydata_peaks.diminfo[0].strides = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_peaks.diminfo[0].shape = __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 349, __pyx_L1_error)
  }
  __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_ydata_peaks, ((PyArrayObject *)__pyx_t_3));
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":351
 *     ydata_peaks /= ydata_peaks.max()
 * 
 *     peaks_found = {}             # <<<<<<<<<<<<<<
 *     if peak_width_start > peak_width_end:
 *         peak_width_start = peak_width_end
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_peaks_found = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":352
 * 
 *     peaks_found = {}
 *     if peak_width_start > peak_width_end:             # <<<<<<<<<<<<<<
 *         peak_width_start = peak_width_end
 *     peak_width = peak_width_start
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_peak_width_start, __pyx_v_peak_width_end, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error)
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_10) {

    /* "pyquant/cpeaks.pyx":353
 *     peaks_found = {}
 *     if peak_width_start > peak_width_end:
 *         peak_width_start = peak_width_end             # <<<<<<<<<<<<<<
 *     peak_width = peak_width_start
 *     while peak_width <= peak_width_end:
 */
    __Pyx_INCREF(__pyx_v_peak_width_end);
    __Pyx_DECREF_SET(__pyx_v_peak_width_start, __pyx_v_peak_width_end);

    /* "pyquant/cpeaks.pyx":352
 * 
 *     peaks_found = {}
 *     if peak_width_start > peak_width_end:             # <<<<<<<<<<<<<<
 *         peak_width_start = peak_width_end
 *     peak_width = peak_width_start
 */
  }

  /* "pyquant/cpeaks.pyx":354
 *     if peak_width_start > peak_width_end:
 *         peak_width_start = peak_width_end
 *     peak_width = peak_width_start             # <<<<<<<<<<<<<<
 *     while peak_width <= peak_width_end:
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)
 */
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_peak_width_start); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 354, __pyx_L1_error)
  __pyx_v_peak_width = __pyx_t_5;

  /* "pyquant/cpeaks.pyx":355
 *         peak_width_start = peak_width_end
 *     peak_width = peak_width_start
 *     while peak_width <= peak_width_end:             # <<<<<<<<<<<<<<
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)
 *         if not row_peaks.size:
 */
  while (1) {
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_v_peak_width_end, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_10) break;

    /* "pyquant/cpeaks.pyx":356
 *     peak_width = peak_width_start
 *     while peak_width <= peak_width_end:
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)             # <<<<<<<<<<<<<<
 *         if not row_peaks.size:
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_argrelmax); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_ydata_peaks));
    __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_order, __pyx_t_9) < 0) __PYX_ERR(0, 356, __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_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 356, __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_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_GetItemInt(__pyx_t_9, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_13);
    __pyx_t_13 = 0;
    __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 356, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, __pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 356, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
      __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_5 < 0)) {
        PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        }
      }
      __pyx_pybuffernd_row_peaks.diminfo[0].strides = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_peaks.diminfo[0].shape = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 356, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_row_peaks, ((PyArrayObject *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":357
 *     while peak_width <= peak_width_end:
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)
 *         if not row_peaks.size:             # <<<<<<<<<<<<<<
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 *         if debug:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_row_peaks), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 357, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_17 = ((!__pyx_t_10) != 0);
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":358
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)
 *         if not row_peaks.size:
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)             # <<<<<<<<<<<<<<
 *         if debug:
 *             sys.stderr.write('{}'.format(row_peaks))
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_argmax); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_9) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_ydata)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __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_ydata));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
        PyTuple_SET_ITEM(__pyx_t_1, 0+1, ((PyObject *)__pyx_v_ydata));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 358, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 358, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
        __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_5 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
          }
        }
        __pyx_pybuffernd_row_peaks.diminfo[0].strides = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_peaks.diminfo[0].shape = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 358, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF_SET(__pyx_v_row_peaks, ((PyArrayObject *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":357
 *     while peak_width <= peak_width_end:
 *         row_peaks = np.array(argrelmax(ydata_peaks, order=peak_width)[0], dtype=int)
 *         if not row_peaks.size:             # <<<<<<<<<<<<<<
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 *         if debug:
 */
    }

    /* "pyquant/cpeaks.pyx":359
 *         if not row_peaks.size:
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 *         if debug:             # <<<<<<<<<<<<<<
 *             sys.stderr.write('{}'.format(row_peaks))
 *         # Max peaks is to avoid spending a significant amount of time fitting bad data. It can lead to problems
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 359, __pyx_L1_error)
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":360
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 *         if debug:
 *             sys.stderr.write('{}'.format(row_peaks))             # <<<<<<<<<<<<<<
 *         # Max peaks is to avoid spending a significant amount of time fitting bad data. It can lead to problems
 *         # if the user is searching the entire ms spectra because of the number of peaks possible to find
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 360, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_stderr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 360, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__18, __pyx_n_s_format); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 360, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_9 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
        }
      }
      if (!__pyx_t_9) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_row_peaks)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); __pyx_t_9 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_row_peaks));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_row_peaks));
        PyTuple_SET_ITEM(__pyx_t_15, 0+1, ((PyObject *)__pyx_v_row_peaks));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_13) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":359
 *         if not row_peaks.size:
 *             row_peaks = np.array([np.argmax(ydata)], dtype=int)
 *         if debug:             # <<<<<<<<<<<<<<
 *             sys.stderr.write('{}'.format(row_peaks))
 *         # Max peaks is to avoid spending a significant amount of time fitting bad data. It can lead to problems
 */
    }

    /* "pyquant/cpeaks.pyx":363
 *         # Max peaks is to avoid spending a significant amount of time fitting bad data. It can lead to problems
 *         # if the user is searching the entire ms spectra because of the number of peaks possible to find
 *         if max_peaks != -1 and row_peaks.size > max_peaks:             # <<<<<<<<<<<<<<
 *             # pick the top n peaks for max_peaks
 *             # this selects the row peaks in ydata, reversed the sorting order (to be greatest to least), then
 */
    __pyx_t_10 = ((__pyx_v_max_peaks != -1L) != 0);
    if (__pyx_t_10) {
    } else {
      __pyx_t_17 = __pyx_t_10;
      goto __pyx_L24_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_row_peaks), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_max_peaks); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_15 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_17 = __pyx_t_10;
    __pyx_L24_bool_binop_done:;
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":367
 *             # this selects the row peaks in ydata, reversed the sorting order (to be greatest to least), then
 *             # takes the number of peaks we allow and then sorts those peaks
 *             row_peaks = np.sort(row_peaks[np.argsort(ydata_peaks[row_peaks])[::-1]][:max_peaks])             # <<<<<<<<<<<<<<
 *             #peak_width_end += 1
 *             #peak_width += 1
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sort); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __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_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_argsort); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_ydata_peaks), ((PyObject *)__pyx_v_row_peaks)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
        }
      }
      if (!__pyx_t_9) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_9); __pyx_t_9 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = PyObject_GetItem(__pyx_t_3, __pyx_slice__19); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_row_peaks), __pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = __Pyx_PyObject_GetSlice(__pyx_t_3, 0, __pyx_v_max_peaks, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_13); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_GOTREF(__pyx_t_15);
      } else {
        __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_13);
        __pyx_t_13 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 367, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 367, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_15);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
        __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_5 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_row_peaks.diminfo[0].strides = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_peaks.diminfo[0].shape = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 367, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF_SET(__pyx_v_row_peaks, ((PyArrayObject *)__pyx_t_15));
      __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":363
 *         # Max peaks is to avoid spending a significant amount of time fitting bad data. It can lead to problems
 *         # if the user is searching the entire ms spectra because of the number of peaks possible to find
 *         if max_peaks != -1 and row_peaks.size > max_peaks:             # <<<<<<<<<<<<<<
 *             # pick the top n peaks for max_peaks
 *             # this selects the row peaks in ydata, reversed the sorting order (to be greatest to least), then
 */
    }

    /* "pyquant/cpeaks.pyx":371
 *             #peak_width += 1
 *             #continue
 *         if ydata_peaks.size:             # <<<<<<<<<<<<<<
 *             minima = np.where(ydata_peaks==0)[0].tolist()
 *         else:
 */
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata_peaks), __pyx_n_s_size); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 371, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 371, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":372
 *             #continue
 *         if ydata_peaks.size:
 *             minima = np.where(ydata_peaks==0)[0].tolist()             # <<<<<<<<<<<<<<
 *         else:
 *             minima = []
 */
      __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_where); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata_peaks), __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 372, __pyx_L1_error)
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_GIVEREF(__pyx_t_14);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_14);
        __pyx_t_14 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_tolist); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (__pyx_t_13) {
        __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_13); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 372, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else {
        __pyx_t_15 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 372, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_15))||((__pyx_t_15) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_15)->tp_name), 0))) __PYX_ERR(0, 372, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_minima, ((PyObject*)__pyx_t_15));
      __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":371
 *             #peak_width += 1
 *             #continue
 *         if ydata_peaks.size:             # <<<<<<<<<<<<<<
 *             minima = np.where(ydata_peaks==0)[0].tolist()
 *         else:
 */
      goto __pyx_L26;
    }

    /* "pyquant/cpeaks.pyx":374
 *             minima = np.where(ydata_peaks==0)[0].tolist()
 *         else:
 *             minima = []             # <<<<<<<<<<<<<<
 *         minima.extend([i for i in argrelmin(ydata_peaks, order=peak_width)[0] if i not in minima and i not in row_peaks])
 *         minima.sort()
 */
    /*else*/ {
      __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 374, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_XDECREF_SET(__pyx_v_minima, ((PyObject*)__pyx_t_15));
      __pyx_t_15 = 0;
    }
    __pyx_L26:;

    /* "pyquant/cpeaks.pyx":375
 *         else:
 *             minima = []
 *         minima.extend([i for i in argrelmin(ydata_peaks, order=peak_width)[0] if i not in minima and i not in row_peaks])             # <<<<<<<<<<<<<<
 *         minima.sort()
 *         peaks_found[peak_width] = {'peaks': row_peaks, 'minima': minima}
 */
    if (unlikely(__pyx_v_minima == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "extend");
      __PYX_ERR(0, 375, __pyx_L1_error)
    }
    __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_argrelmin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata_peaks));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata_peaks));
    PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_v_ydata_peaks));
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_order, __pyx_t_14) < 0) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_14, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_14 = __pyx_t_2; __Pyx_INCREF(__pyx_t_14); __pyx_t_11 = 0;
      __pyx_t_18 = NULL;
    } else {
      __pyx_t_11 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_18 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 375, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_18)) {
        if (likely(PyList_CheckExact(__pyx_t_14))) {
          if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_14)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 375, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_14, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_14)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 375, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_14, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_18(__pyx_t_14);
        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, 375, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_i = __pyx_t_5;
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_minima, Py_NE)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_19 = (__pyx_t_10 != 0);
      if (__pyx_t_19) {
      } else {
        __pyx_t_17 = __pyx_t_19;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_19 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, ((PyObject *)__pyx_v_row_peaks), Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 375, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = (__pyx_t_19 != 0);
      __pyx_t_17 = __pyx_t_10;
      __pyx_L30_bool_binop_done:;
      if (__pyx_t_17) {
        __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_15, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 375, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_minima, __pyx_t_15); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 375, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pyquant/cpeaks.pyx":376
 *             minima = []
 *         minima.extend([i for i in argrelmin(ydata_peaks, order=peak_width)[0] if i not in minima and i not in row_peaks])
 *         minima.sort()             # <<<<<<<<<<<<<<
 *         peaks_found[peak_width] = {'peaks': row_peaks, 'minima': minima}
 *         # if row_peaks.size > 1:
 */
    if (unlikely(__pyx_v_minima == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "sort");
      __PYX_ERR(0, 376, __pyx_L1_error)
    }
    __pyx_t_20 = PyList_Sort(__pyx_v_minima); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 376, __pyx_L1_error)

    /* "pyquant/cpeaks.pyx":377
 *         minima.extend([i for i in argrelmin(ydata_peaks, order=peak_width)[0] if i not in minima and i not in row_peaks])
 *         minima.sort()
 *         peaks_found[peak_width] = {'peaks': row_peaks, 'minima': minima}             # <<<<<<<<<<<<<<
 *         # if row_peaks.size > 1:
 *         #     peak_width_end += 1
 */
    __pyx_t_15 = PyDict_New(); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 377, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_peaks, ((PyObject *)__pyx_v_row_peaks)) < 0) __PYX_ERR(0, 377, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_minima, __pyx_v_minima) < 0) __PYX_ERR(0, 377, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 377, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (unlikely(PyDict_SetItem(__pyx_v_peaks_found, __pyx_t_14, __pyx_t_15) < 0)) __PYX_ERR(0, 377, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pyquant/cpeaks.pyx":380
 *         # if row_peaks.size > 1:
 *         #     peak_width_end += 1
 *         peak_width += 1             # <<<<<<<<<<<<<<
 *     # collapse identical orders
 *     if debug:
 */
    __pyx_v_peak_width = (__pyx_v_peak_width + 1);
  }

  /* "pyquant/cpeaks.pyx":382
 *         peak_width += 1
 *     # collapse identical orders
 *     if debug:             # <<<<<<<<<<<<<<
 *         sys.stderr.write('found: {}\n'.format(peaks_found))
 *     final_peaks = {}
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 382, __pyx_L1_error)
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":383
 *     # collapse identical orders
 *     if debug:
 *         sys.stderr.write('found: {}\n'.format(peaks_found))             # <<<<<<<<<<<<<<
 *     final_peaks = {}
 *     if peak_width_start == peak_width_end:
 */
    __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 383, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_stderr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_write); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 383, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_found, __pyx_n_s_format); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 383, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_13))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_13);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_13, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_peaks_found); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __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 = NULL;
      __Pyx_INCREF(__pyx_v_peaks_found);
      __Pyx_GIVEREF(__pyx_v_peaks_found);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_peaks_found);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_14, function);
      }
    }
    if (!__pyx_t_13) {
      __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_15);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); __pyx_t_13 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pyquant/cpeaks.pyx":382
 *         peak_width += 1
 *     # collapse identical orders
 *     if debug:             # <<<<<<<<<<<<<<
 *         sys.stderr.write('found: {}\n'.format(peaks_found))
 *     final_peaks = {}
 */
  }

  /* "pyquant/cpeaks.pyx":384
 *     if debug:
 *         sys.stderr.write('found: {}\n'.format(peaks_found))
 *     final_peaks = {}             # <<<<<<<<<<<<<<
 *     if peak_width_start == peak_width_end:
 *         final_peaks = peaks_found
 */
  __pyx_t_15 = PyDict_New(); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 384, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_v_final_peaks = ((PyObject*)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":385
 *         sys.stderr.write('found: {}\n'.format(peaks_found))
 *     final_peaks = {}
 *     if peak_width_start == peak_width_end:             # <<<<<<<<<<<<<<
 *         final_peaks = peaks_found
 *     else:
 */
  __pyx_t_15 = PyObject_RichCompare(__pyx_v_peak_width_start, __pyx_v_peak_width_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 385, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":386
 *     final_peaks = {}
 *     if peak_width_start == peak_width_end:
 *         final_peaks = peaks_found             # <<<<<<<<<<<<<<
 *     else:
 *         for peak_width in xrange(peak_width_start, peak_width_end):
 */
    __Pyx_INCREF(__pyx_v_peaks_found);
    __Pyx_DECREF_SET(__pyx_v_final_peaks, __pyx_v_peaks_found);

    /* "pyquant/cpeaks.pyx":385
 *         sys.stderr.write('found: {}\n'.format(peaks_found))
 *     final_peaks = {}
 *     if peak_width_start == peak_width_end:             # <<<<<<<<<<<<<<
 *         final_peaks = peaks_found
 *     else:
 */
    goto __pyx_L33;
  }

  /* "pyquant/cpeaks.pyx":388
 *         final_peaks = peaks_found
 *     else:
 *         for peak_width in xrange(peak_width_start, peak_width_end):             # <<<<<<<<<<<<<<
 *             if debug:
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 */
  /*else*/ {
    __pyx_t_21 = __Pyx_PyInt_As_long(__pyx_v_peak_width_end); if (unlikely((__pyx_t_21 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 388, __pyx_L1_error)
    __pyx_t_22 = __Pyx_PyInt_As_long(__pyx_v_peak_width_start); if (unlikely((__pyx_t_22 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 388, __pyx_L1_error)
    for (__pyx_t_5 = __pyx_t_22; __pyx_t_5 < __pyx_t_21; __pyx_t_5+=1) {
      __pyx_v_peak_width = __pyx_t_5;

      /* "pyquant/cpeaks.pyx":389
 *     else:
 *         for peak_width in xrange(peak_width_start, peak_width_end):
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 *             if peak_width not in peaks_found:
 */
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 389, __pyx_L1_error)
      if (__pyx_t_17) {

        /* "pyquant/cpeaks.pyx":390
 *         for peak_width in xrange(peak_width_start, peak_width_end):
 *             if debug:
 *                 sys.stderr.write('checking {}\n'.format(peak_width))             # <<<<<<<<<<<<<<
 *             if peak_width not in peaks_found:
 *                 continue
 */
        __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_stderr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_write); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_checking, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_1 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        if (!__pyx_t_1) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 390, __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_13);
          PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_13);
          __pyx_t_13 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_14);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_14, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 390, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_15);
        } else {
          __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 390, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_9, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 390, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "pyquant/cpeaks.pyx":389
 *     else:
 *         for peak_width in xrange(peak_width_start, peak_width_end):
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 *             if peak_width not in peaks_found:
 */
      }

      /* "pyquant/cpeaks.pyx":391
 *             if debug:
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 *             if peak_width not in peaks_found:             # <<<<<<<<<<<<<<
 *                 continue
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 */
      __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 391, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_17 = (__Pyx_PyDict_ContainsTF(__pyx_t_15, __pyx_v_peaks_found, Py_NE)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 391, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_10 = (__pyx_t_17 != 0);
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":392
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 *             if peak_width not in peaks_found:
 *                 continue             # <<<<<<<<<<<<<<
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']
 */
        goto __pyx_L34_continue;

        /* "pyquant/cpeaks.pyx":391
 *             if debug:
 *                 sys.stderr.write('checking {}\n'.format(peak_width))
 *             if peak_width not in peaks_found:             # <<<<<<<<<<<<<<
 *                 continue
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 */
      }

      /* "pyquant/cpeaks.pyx":393
 *             if peak_width not in peaks_found:
 *                 continue
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']             # <<<<<<<<<<<<<<
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']
 *             if debug:
 */
      __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = PyObject_GetItem(__pyx_t_14, __pyx_n_s_peaks); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 393, __pyx_L1_error)
      __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_9 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = PyObject_GetItem(__pyx_t_9, __pyx_n_s_minima); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 393, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_14))||((__pyx_t_14) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_14)->tp_name), 0))) __PYX_ERR(0, 393, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_15);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer);
        __pyx_t_23 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_23 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_smaller_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
          }
        }
        __pyx_pybuffernd_smaller_peaks.diminfo[0].strides = __pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_smaller_peaks.diminfo[0].shape = __pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_23 < 0)) __PYX_ERR(0, 393, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_smaller_peaks, ((PyArrayObject *)__pyx_t_15));
      __pyx_t_15 = 0;
      __Pyx_XDECREF_SET(__pyx_v_smaller_minima, ((PyObject*)__pyx_t_14));
      __pyx_t_14 = 0;

      /* "pyquant/cpeaks.pyx":394
 *                 continue
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']             # <<<<<<<<<<<<<<
 *             if debug:
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 */
      __pyx_t_14 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_15 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = PyObject_GetItem(__pyx_t_15, __pyx_n_s_peaks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (!(likely(((__pyx_t_14) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_14, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 394, __pyx_L1_error)
      __pyx_t_15 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_9 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = PyObject_GetItem(__pyx_t_9, __pyx_n_s_minima); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_15))||((__pyx_t_15) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_15)->tp_name), 0))) __PYX_ERR(0, 394, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_14);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer);
        __pyx_t_23 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_23 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_larger_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_larger_peaks.diminfo[0].strides = __pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_larger_peaks.diminfo[0].shape = __pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_23 < 0)) __PYX_ERR(0, 394, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_larger_peaks, ((PyArrayObject *)__pyx_t_14));
      __pyx_t_14 = 0;
      __Pyx_XDECREF_SET(__pyx_v_larger_minima, ((PyObject*)__pyx_t_15));
      __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":395
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 */
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 395, __pyx_L1_error)
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":396
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']
 *             if debug:
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))             # <<<<<<<<<<<<<<
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 */
        __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_stderr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_write); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__20, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_13 = NULL;
        __pyx_t_11 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_11 = 1;
          }
        }
        __pyx_t_1 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_13) {
          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_13); __pyx_t_13 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_t_2);
        __Pyx_INCREF(((PyObject *)__pyx_v_smaller_peaks));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_smaller_peaks));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, ((PyObject *)__pyx_v_smaller_peaks));
        __Pyx_INCREF(((PyObject *)__pyx_v_larger_peaks));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_larger_peaks));
        PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_11, ((PyObject *)__pyx_v_larger_peaks));
        __pyx_t_2 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 396, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_14, function);
          }
        }
        if (!__pyx_t_3) {
          __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_9); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 396, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_15);
        } else {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
          __Pyx_GIVEREF(__pyx_t_9);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_9);
          __pyx_t_9 = 0;
          __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 396, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "pyquant/cpeaks.pyx":395
 *             smaller_peaks, smaller_minima = peaks_found[peak_width]['peaks'],peaks_found[peak_width]['minima']
 *             larger_peaks, larger_minima = peaks_found[peak_width+1]['peaks'],peaks_found[peak_width+1]['minima']
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 */
      }

      /* "pyquant/cpeaks.pyx":397
 *             if debug:
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):             # <<<<<<<<<<<<<<
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 *                 if peak_width in final_peaks:
 */
      __pyx_t_15 = PySet_New(((PyObject *)__pyx_v_smaller_peaks)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_14 = PySet_New(((PyObject *)__pyx_v_larger_peaks)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_15, __pyx_t_14, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L40_bool_binop_done;
      }
      __pyx_t_1 = PySet_New(__pyx_v_smaller_minima); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = PySet_New(__pyx_v_larger_minima); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_15 = PyObject_RichCompare(__pyx_t_1, __pyx_t_14, Py_EQ); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_10 = __pyx_t_17;
      __pyx_L40_bool_binop_done:;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":398
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]             # <<<<<<<<<<<<<<
 *                 if peak_width in final_peaks:
 *                     del final_peaks[peak_width]
 */
        __pyx_t_15 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 398, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 398, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_15 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 398, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (unlikely(PyDict_SetItem(__pyx_v_final_peaks, __pyx_t_15, __pyx_t_14) < 0)) __PYX_ERR(0, 398, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "pyquant/cpeaks.pyx":399
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 *                 if peak_width in final_peaks:             # <<<<<<<<<<<<<<
 *                     del final_peaks[peak_width]
 *             else:
 */
        __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 399, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_10 = (__Pyx_PyDict_ContainsTF(__pyx_t_14, __pyx_v_final_peaks, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 399, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_17 = (__pyx_t_10 != 0);
        if (__pyx_t_17) {

          /* "pyquant/cpeaks.pyx":400
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 *                 if peak_width in final_peaks:
 *                     del final_peaks[peak_width]             # <<<<<<<<<<<<<<
 *             else:
 *                 final_peaks[peak_width] = peaks_found[peak_width]
 */
          __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 400, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (unlikely(PyDict_DelItem(__pyx_v_final_peaks, __pyx_t_14) < 0)) __PYX_ERR(0, 400, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

          /* "pyquant/cpeaks.pyx":399
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 *                 if peak_width in final_peaks:             # <<<<<<<<<<<<<<
 *                     del final_peaks[peak_width]
 *             else:
 */
        }

        /* "pyquant/cpeaks.pyx":397
 *             if debug:
 *                 sys.stderr.write('{}: {} ---- {}\n'.format(peak_width, smaller_peaks, larger_peaks))
 *             if set(smaller_peaks) == set(larger_peaks) and set(smaller_minima) ==  set(larger_minima):             # <<<<<<<<<<<<<<
 *                 final_peaks[peak_width+1] = peaks_found[peak_width+1]
 *                 if peak_width in final_peaks:
 */
        goto __pyx_L39;
      }

      /* "pyquant/cpeaks.pyx":402
 *                     del final_peaks[peak_width]
 *             else:
 *                 final_peaks[peak_width] = peaks_found[peak_width]             # <<<<<<<<<<<<<<
 *                 if peak_width == peak_width_end-1:
 *                     final_peaks[peak_width+1] = peaks_found[peak_width+1]
 */
      /*else*/ {
        __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_15 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        if (unlikely(PyDict_SetItem(__pyx_v_final_peaks, __pyx_t_14, __pyx_t_15) < 0)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "pyquant/cpeaks.pyx":403
 *             else:
 *                 final_peaks[peak_width] = peaks_found[peak_width]
 *                 if peak_width == peak_width_end-1:             # <<<<<<<<<<<<<<
 *                     final_peaks[peak_width+1] = peaks_found[peak_width+1]
 * 
 */
        __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_peak_width); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 403, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_14 = __Pyx_PyInt_SubtractObjC(__pyx_v_peak_width_end, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 403, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_1 = PyObject_RichCompare(__pyx_t_15, __pyx_t_14, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 403, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_17) {

          /* "pyquant/cpeaks.pyx":404
 *                 final_peaks[peak_width] = peaks_found[peak_width]
 *                 if peak_width == peak_width_end-1:
 *                     final_peaks[peak_width+1] = peaks_found[peak_width+1]             # <<<<<<<<<<<<<<
 * 
 *     cdef tuple args
 */
          __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_peaks_found, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 404, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_peak_width + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (unlikely(PyDict_SetItem(__pyx_v_final_peaks, __pyx_t_1, __pyx_t_14) < 0)) __PYX_ERR(0, 404, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

          /* "pyquant/cpeaks.pyx":403
 *             else:
 *                 final_peaks[peak_width] = peaks_found[peak_width]
 *                 if peak_width == peak_width_end-1:             # <<<<<<<<<<<<<<
 *                     final_peaks[peak_width+1] = peaks_found[peak_width+1]
 * 
 */
        }
      }
      __pyx_L39:;
      __pyx_L34_continue:;
    }
  }
  __pyx_L33:;

  /* "pyquant/cpeaks.pyx":411
 *     cdef str routine
 *     cdef object res, best_res
 *     best_res = 0             # <<<<<<<<<<<<<<
 *     cdef float bic, n, k, lowest_bic
 *     cdef float min_val
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_best_res = __pyx_int_0;

  /* "pyquant/cpeaks.pyx":415
 *     cdef float min_val
 * 
 *     fit_accuracy = []             # <<<<<<<<<<<<<<
 *     min_spacing = min(np.diff(xdata))/2
 *     peak_range = xdata[-1]-xdata[0]
 */
  __pyx_t_14 = PyList_New(0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_v_fit_accuracy = ((PyObject*)__pyx_t_14);
  __pyx_t_14 = 0;

  /* "pyquant/cpeaks.pyx":416
 * 
 *     fit_accuracy = []
 *     min_spacing = min(np.diff(xdata))/2             # <<<<<<<<<<<<<<
 *     peak_range = xdata[-1]-xdata[0]
 *     # initial bound setup
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_diff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_15, ((PyObject *)__pyx_v_xdata)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 416, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
  } else {
    __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 416, __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_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_9, 0+1, ((PyObject *)__pyx_v_xdata));
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_9, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 416, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_14);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14);
  __pyx_t_14 = 0;
  __pyx_t_14 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_14, __pyx_int_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_v_min_spacing = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":417
 *     fit_accuracy = []
 *     min_spacing = min(np.diff(xdata))/2
 *     peak_range = xdata[-1]-xdata[0]             # <<<<<<<<<<<<<<
 *     # initial bound setup
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]
 */
  __pyx_t_24 = -1L;
  if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_pybuffernd_xdata.diminfo[0].shape;
  __pyx_t_25 = 0;
  if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_pybuffernd_xdata.diminfo[0].shape;
  __pyx_t_15 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_xdata.diminfo[0].strides)) - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_xdata.diminfo[0].strides)))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_v_peak_range = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":419
 *     peak_range = xdata[-1]-xdata[0]
 *     # initial bound setup
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]             # <<<<<<<<<<<<<<
 *     if bigauss_fit:
 *         initial_bounds.extend([(min_spacing, peak_range)])
 */
  __pyx_t_26 = 0;
  if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_pybuffernd_xdata.diminfo[0].shape;
  __pyx_t_15 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_27 = -1L;
  if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_pybuffernd_xdata.diminfo[0].shape;
  __pyx_t_14 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_14);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_14);
  __pyx_t_15 = 0;
  __pyx_t_14 = 0;
  __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_INCREF(__pyx_v_min_spacing);
  __Pyx_GIVEREF(__pyx_v_min_spacing);
  PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_min_spacing);
  __Pyx_INCREF(__pyx_v_peak_range);
  __Pyx_GIVEREF(__pyx_v_peak_range);
  PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_peak_range);
  __pyx_t_15 = PyList_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_INCREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_15, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_14);
  PyList_SET_ITEM(__pyx_t_15, 2, __pyx_t_14);
  __pyx_t_9 = 0;
  __pyx_t_14 = 0;
  __pyx_v_initial_bounds = ((PyObject*)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":420
 *     # initial bound setup
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]
 *     if bigauss_fit:             # <<<<<<<<<<<<<<
 *         initial_bounds.extend([(min_spacing, peak_range)])
 *         # print(final_peaks)
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 420, __pyx_L1_error)
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":421
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]
 *     if bigauss_fit:
 *         initial_bounds.extend([(min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *         # print(final_peaks)
 *     lowest_bic = 9999.
 */
    __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_INCREF(__pyx_v_min_spacing);
    __Pyx_GIVEREF(__pyx_v_min_spacing);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_min_spacing);
    __Pyx_INCREF(__pyx_v_peak_range);
    __Pyx_GIVEREF(__pyx_v_peak_range);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_peak_range);
    __pyx_t_14 = PyList_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_15);
    PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_15);
    __pyx_t_15 = 0;
    __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_initial_bounds, __pyx_t_14); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "pyquant/cpeaks.pyx":420
 *     # initial bound setup
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]
 *     if bigauss_fit:             # <<<<<<<<<<<<<<
 *         initial_bounds.extend([(min_spacing, peak_range)])
 *         # print(final_peaks)
 */
  }

  /* "pyquant/cpeaks.pyx":423
 *         initial_bounds.extend([(min_spacing, peak_range)])
 *         # print(final_peaks)
 *     lowest_bic = 9999.             # <<<<<<<<<<<<<<
 *     if debug:
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 */
  __pyx_v_lowest_bic = 9999.;

  /* "pyquant/cpeaks.pyx":424
 *         # print(final_peaks)
 *     lowest_bic = 9999.
 *     if debug:             # <<<<<<<<<<<<<<
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 *     for peak_width, peak_info in final_peaks.items():
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 424, __pyx_L1_error)
  if (__pyx_t_17) {

    /* "pyquant/cpeaks.pyx":425
 *     lowest_bic = 9999.
 *     if debug:
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))             # <<<<<<<<<<<<<<
 *     for peak_width, peak_info in final_peaks.items():
 *         row_peaks = peak_info['peaks']
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 425, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_stderr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 425, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_write); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 425, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_final_peaks, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 425, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_final_peaks); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_final_peaks);
      __Pyx_GIVEREF(__pyx_v_final_peaks);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_final_peaks);
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_14);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 425, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "pyquant/cpeaks.pyx":424
 *         # print(final_peaks)
 *     lowest_bic = 9999.
 *     if debug:             # <<<<<<<<<<<<<<
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 *     for peak_width, peak_info in final_peaks.items():
 */
  }

  /* "pyquant/cpeaks.pyx":426
 *     if debug:
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 *     for peak_width, peak_info in final_peaks.items():             # <<<<<<<<<<<<<<
 *         row_peaks = peak_info['peaks']
 *         if debug:
 */
  __pyx_t_14 = __Pyx_PyDict_Items(__pyx_v_final_peaks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  if (likely(PyList_CheckExact(__pyx_t_14)) || PyTuple_CheckExact(__pyx_t_14)) {
    __pyx_t_15 = __pyx_t_14; __Pyx_INCREF(__pyx_t_15); __pyx_t_11 = 0;
    __pyx_t_18 = NULL;
  } else {
    __pyx_t_11 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 426, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_18 = Py_TYPE(__pyx_t_15)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 426, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  for (;;) {
    if (likely(!__pyx_t_18)) {
      if (likely(PyList_CheckExact(__pyx_t_15))) {
        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_15)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_14 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_11); __Pyx_INCREF(__pyx_t_14); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 426, __pyx_L1_error)
        #else
        __pyx_t_14 = PySequence_ITEM(__pyx_t_15, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 426, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
      } else {
        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_15)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_11); __Pyx_INCREF(__pyx_t_14); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 426, __pyx_L1_error)
        #else
        __pyx_t_14 = PySequence_ITEM(__pyx_t_15, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 426, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
      }
    } else {
      __pyx_t_14 = __pyx_t_18(__pyx_t_15);
      if (unlikely(!__pyx_t_14)) {
        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, 426, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_14);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) {
      PyObject* sequence = __pyx_t_14;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 426, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_1 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_28 = Py_TYPE(__pyx_t_1)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_28(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L48_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_9 = __pyx_t_28(__pyx_t_1); if (unlikely(!__pyx_t_9)) goto __pyx_L48_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_28(__pyx_t_1), 2) < 0) __PYX_ERR(0, 426, __pyx_L1_error)
      __pyx_t_28 = NULL;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L49_unpacking_done;
      __pyx_L48_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_28 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 426, __pyx_L1_error)
      __pyx_L49_unpacking_done:;
    }
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 426, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyDict_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_9)->tp_name), 0))) __PYX_ERR(0, 426, __pyx_L1_error)
    __pyx_v_peak_width = __pyx_t_5;
    __Pyx_XDECREF_SET(__pyx_v_peak_info, ((PyObject*)__pyx_t_9));
    __pyx_t_9 = 0;

    /* "pyquant/cpeaks.pyx":427
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 *     for peak_width, peak_info in final_peaks.items():
 *         row_peaks = peak_info['peaks']             # <<<<<<<<<<<<<<
 *         if debug:
 *             print 'analyzing', row_peaks
 */
    if (unlikely(__pyx_v_peak_info == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 427, __pyx_L1_error)
    }
    __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_peak_info, __pyx_n_s_peaks); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 427, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (!(likely(((__pyx_t_14) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_14, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 427, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_14);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
      __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_5 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_peaks, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
        }
      }
      __pyx_pybuffernd_row_peaks.diminfo[0].strides = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_peaks.diminfo[0].shape = __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 427, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_row_peaks, ((PyArrayObject *)__pyx_t_14));
    __pyx_t_14 = 0;

    /* "pyquant/cpeaks.pyx":428
 *     for peak_width, peak_info in final_peaks.items():
 *         row_peaks = peak_info['peaks']
 *         if debug:             # <<<<<<<<<<<<<<
 *             print 'analyzing', row_peaks
 *         minima_array = np.array(peak_info['minima'], dtype=long)
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 428, __pyx_L1_error)
    if (__pyx_t_17) {

      /* "pyquant/cpeaks.pyx":429
 *         row_peaks = peak_info['peaks']
 *         if debug:
 *             print 'analyzing', row_peaks             # <<<<<<<<<<<<<<
 *         minima_array = np.array(peak_info['minima'], dtype=long)
 *         guess = []
 */
      __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 429, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_INCREF(__pyx_n_s_analyzing);
      __Pyx_GIVEREF(__pyx_n_s_analyzing);
      PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_n_s_analyzing);
      __Pyx_INCREF(((PyObject *)__pyx_v_row_peaks));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_row_peaks));
      PyTuple_SET_ITEM(__pyx_t_14, 1, ((PyObject *)__pyx_v_row_peaks));
      if (__Pyx_Print(0, __pyx_t_14, 1) < 0) __PYX_ERR(0, 429, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

      /* "pyquant/cpeaks.pyx":428
 *     for peak_width, peak_info in final_peaks.items():
 *         row_peaks = peak_info['peaks']
 *         if debug:             # <<<<<<<<<<<<<<
 *             print 'analyzing', row_peaks
 *         minima_array = np.array(peak_info['minima'], dtype=long)
 */
    }

    /* "pyquant/cpeaks.pyx":430
 *         if debug:
 *             print 'analyzing', row_peaks
 *         minima_array = np.array(peak_info['minima'], dtype=long)             # <<<<<<<<<<<<<<
 *         guess = []
 *         bnds = []
 */
    __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    if (unlikely(__pyx_v_peak_info == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 430, __pyx_L1_error)
    }
    __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_peak_info, __pyx_n_s_minima); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14);
    __pyx_t_14 = 0;
    __pyx_t_14 = PyDict_New(); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_dtype, ((PyObject *)(&PyLong_Type))) < 0) __PYX_ERR(0, 430, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 430, __pyx_L1_error)
    __pyx_t_29 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minima_array.rcbuffer->pybuffer);
      __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_minima_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_29, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_5 < 0)) {
        PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_minima_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_minima_array, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        }
      }
      __pyx_pybuffernd_minima_array.diminfo[0].strides = __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_minima_array.diminfo[0].shape = __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 430, __pyx_L1_error)
    }
    __pyx_t_29 = 0;
    __Pyx_XDECREF_SET(__pyx_v_minima_array, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":431
 *             print 'analyzing', row_peaks
 *         minima_array = np.array(peak_info['minima'], dtype=long)
 *         guess = []             # <<<<<<<<<<<<<<
 *         bnds = []
 *         last_peak = -1
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_guess, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":432
 *         minima_array = np.array(peak_info['minima'], dtype=long)
 *         guess = []
 *         bnds = []             # <<<<<<<<<<<<<<
 *         last_peak = -1
 *         skip_peaks = set([])
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_bnds, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":433
 *         guess = []
 *         bnds = []
 *         last_peak = -1             # <<<<<<<<<<<<<<
 *         skip_peaks = set([])
 *         fitted_peaks = []
 */
    __pyx_v_last_peak = -1;

    /* "pyquant/cpeaks.pyx":434
 *         bnds = []
 *         last_peak = -1
 *         skip_peaks = set([])             # <<<<<<<<<<<<<<
 *         fitted_peaks = []
 *         for peak_num, peak_index in enumerate(row_peaks):
 */
    __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 434, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_skip_peaks, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":435
 *         last_peak = -1
 *         skip_peaks = set([])
 *         fitted_peaks = []             # <<<<<<<<<<<<<<
 *         for peak_num, peak_index in enumerate(row_peaks):
 *             if peak_index in skip_peaks:
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_fitted_peaks, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":436
 *         skip_peaks = set([])
 *         fitted_peaks = []
 *         for peak_num, peak_index in enumerate(row_peaks):             # <<<<<<<<<<<<<<
 *             if peak_index in skip_peaks:
 *                 continue
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_1 = __pyx_int_0;
    if (likely(PyList_CheckExact(((PyObject *)__pyx_v_row_peaks))) || PyTuple_CheckExact(((PyObject *)__pyx_v_row_peaks))) {
      __pyx_t_14 = ((PyObject *)__pyx_v_row_peaks); __Pyx_INCREF(__pyx_t_14); __pyx_t_30 = 0;
      __pyx_t_31 = NULL;
    } else {
      __pyx_t_30 = -1; __pyx_t_14 = PyObject_GetIter(((PyObject *)__pyx_v_row_peaks)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 436, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_31 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 436, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_31)) {
        if (likely(PyList_CheckExact(__pyx_t_14))) {
          if (__pyx_t_30 >= PyList_GET_SIZE(__pyx_t_14)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_30); __Pyx_INCREF(__pyx_t_2); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 436, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_14, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_30 >= PyTuple_GET_SIZE(__pyx_t_14)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_30); __Pyx_INCREF(__pyx_t_2); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 436, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_14, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_31(__pyx_t_14);
        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, 436, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_peak_index, __pyx_t_2);
      __pyx_t_2 = 0;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_peak_num, __pyx_t_1);
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1);
      __pyx_t_1 = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":437
 *         fitted_peaks = []
 *         for peak_num, peak_index in enumerate(row_peaks):
 *             if peak_index in skip_peaks:             # <<<<<<<<<<<<<<
 *                 continue
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]
 */
      __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_v_peak_index, __pyx_v_skip_peaks, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 437, __pyx_L1_error)
      __pyx_t_10 = (__pyx_t_17 != 0);
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":438
 *         for peak_num, peak_index in enumerate(row_peaks):
 *             if peak_index in skip_peaks:
 *                 continue             # <<<<<<<<<<<<<<
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]
 *             fitted_peaks.append(peak_index)
 */
        goto __pyx_L51_continue;

        /* "pyquant/cpeaks.pyx":437
 *         fitted_peaks = []
 *         for peak_num, peak_index in enumerate(row_peaks):
 *             if peak_index in skip_peaks:             # <<<<<<<<<<<<<<
 *                 continue
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]
 */
      }

      /* "pyquant/cpeaks.pyx":439
 *             if peak_index in skip_peaks:
 *                 continue
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]             # <<<<<<<<<<<<<<
 *             fitted_peaks.append(peak_index)
 *             rel_peak = ydata_peaks[peak_index]
 */
      __pyx_t_32 = -1L;
      if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_pybuffernd_row_peaks.diminfo[0].shape;
      __pyx_t_2 = __Pyx_PyInt_From_long((*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_row_peaks.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_row_peaks.diminfo[0].strides))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_peak_index, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_10) {
        __pyx_t_33 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_33 == -1)) __PYX_ERR(0, 439, __pyx_L1_error)
        __pyx_t_5 = __pyx_t_33;
      } else {
        __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_peak_num, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 439, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_row_peaks), __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 439, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_23 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_5 = __pyx_t_23;
      }
      __pyx_v_next_peak = __pyx_t_5;

      /* "pyquant/cpeaks.pyx":440
 *                 continue
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]
 *             fitted_peaks.append(peak_index)             # <<<<<<<<<<<<<<
 *             rel_peak = ydata_peaks[peak_index]
 *             # find the points around it to estimate the std of the peak
 */
      __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_fitted_peaks, __pyx_v_peak_index); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 440, __pyx_L1_error)

      /* "pyquant/cpeaks.pyx":441
 *             next_peak = len(xdata) if peak_index == row_peaks[-1] else row_peaks[peak_num+1]
 *             fitted_peaks.append(peak_index)
 *             rel_peak = ydata_peaks[peak_index]             # <<<<<<<<<<<<<<
 *             # find the points around it to estimate the std of the peak
 *             if minima_array.size:
 */
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_ydata_peaks), __pyx_v_peak_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 441, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_rel_peak = __pyx_t_12;

      /* "pyquant/cpeaks.pyx":443
 *             rel_peak = ydata_peaks[peak_index]
 *             # find the points around it to estimate the std of the peak
 *             if minima_array.size:             # <<<<<<<<<<<<<<
 *                 left = np.searchsorted(minima_array, peak_index)-1
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_minima_array), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":444
 *             # find the points around it to estimate the std of the peak
 *             if minima_array.size:
 *                 left = np.searchsorted(minima_array, peak_index)-1             # <<<<<<<<<<<<<<
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 *                 if left == -1:
 */
        __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = NULL;
        __pyx_t_33 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_33 = 1;
          }
        }
        __pyx_t_13 = PyTuple_New(2+__pyx_t_33); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_minima_array));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_minima_array));
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_33, ((PyObject *)__pyx_v_minima_array));
        __Pyx_INCREF(__pyx_v_peak_index);
        __Pyx_GIVEREF(__pyx_v_peak_index);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_33, __pyx_v_peak_index);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_left = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":445
 *             if minima_array.size:
 *                 left = np.searchsorted(minima_array, peak_index)-1
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1             # <<<<<<<<<<<<<<
 *                 if left == -1:
 *                     left = 0 if last_peak != -1 else last_peak+1
 */
        if (((__pyx_v_last_peak != -1L) != 0)) {
          __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_last_peak); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_9 = NULL;
          __pyx_t_33 = 0;
          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_13);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_13, function);
              __pyx_t_33 = 1;
            }
          }
          __pyx_t_34 = PyTuple_New(2+__pyx_t_33); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          if (__pyx_t_9) {
            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_t_9); __pyx_t_9 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_v_minima_array));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_minima_array));
          PyTuple_SET_ITEM(__pyx_t_34, 0+__pyx_t_33, ((PyObject *)__pyx_v_minima_array));
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_34, 1+__pyx_t_33, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_34, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_23 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_5 = __pyx_t_23;
        } else {
          __pyx_t_5 = -1;
        }
        __pyx_v_left_stop = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":446
 *                 left = np.searchsorted(minima_array, peak_index)-1
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 *                 if left == -1:             # <<<<<<<<<<<<<<
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:
 */
        __pyx_t_10 = ((__pyx_v_left == -1L) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":447
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 *                 if left == -1:
 *                     left = 0 if last_peak != -1 else last_peak+1             # <<<<<<<<<<<<<<
 *                 elif left == left_stop:
 *                     if last_peak == -1:
 */
          if (((__pyx_v_last_peak != -1L) != 0)) {
            __pyx_t_21 = 0;
          } else {
            __pyx_t_21 = (__pyx_v_last_peak + 1);
          }
          __pyx_v_left = __pyx_t_21;

          /* "pyquant/cpeaks.pyx":446
 *                 left = np.searchsorted(minima_array, peak_index)-1
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 *                 if left == -1:             # <<<<<<<<<<<<<<
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:
 */
          goto __pyx_L55;
        }

        /* "pyquant/cpeaks.pyx":448
 *                 if left == -1:
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:             # <<<<<<<<<<<<<<
 *                     if last_peak == -1:
 *                         left = 0
 */
        __pyx_t_10 = ((__pyx_v_left == __pyx_v_left_stop) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":449
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:
 *                     if last_peak == -1:             # <<<<<<<<<<<<<<
 *                         left = 0
 *                     else:
 */
          __pyx_t_10 = ((__pyx_v_last_peak == -1L) != 0);
          if (__pyx_t_10) {

            /* "pyquant/cpeaks.pyx":450
 *                 elif left == left_stop:
 *                     if last_peak == -1:
 *                         left = 0             # <<<<<<<<<<<<<<
 *                     else:
 *                         left = minima_array[left]
 */
            __pyx_v_left = 0;

            /* "pyquant/cpeaks.pyx":449
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:
 *                     if last_peak == -1:             # <<<<<<<<<<<<<<
 *                         left = 0
 *                     else:
 */
            goto __pyx_L56;
          }

          /* "pyquant/cpeaks.pyx":452
 *                         left = 0
 *                     else:
 *                         left = minima_array[left]             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in xrange(left, left_stop, -1):
 */
          /*else*/ {
            __pyx_t_35 = __pyx_v_left;
            if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_pybuffernd_minima_array.diminfo[0].shape;
            __pyx_v_left = (*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.buf, __pyx_t_35, __pyx_pybuffernd_minima_array.diminfo[0].strides));
          }
          __pyx_L56:;

          /* "pyquant/cpeaks.pyx":448
 *                 if left == -1:
 *                     left = 0 if last_peak != -1 else last_peak+1
 *                 elif left == left_stop:             # <<<<<<<<<<<<<<
 *                     if last_peak == -1:
 *                         left = 0
 */
          goto __pyx_L55;
        }

        /* "pyquant/cpeaks.pyx":454
 *                         left = minima_array[left]
 *                 else:
 *                     for i in xrange(left, left_stop, -1):             # <<<<<<<<<<<<<<
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 */
        /*else*/ {
          __pyx_t_5 = __pyx_v_left_stop;
          for (__pyx_t_23 = __pyx_v_left; __pyx_t_23 > __pyx_t_5; __pyx_t_23-=1) {
            __pyx_v_i = __pyx_t_23;

            /* "pyquant/cpeaks.pyx":455
 *                 else:
 *                     for i in xrange(left, left_stop, -1):
 *                         minima_index = minima_array[i]             # <<<<<<<<<<<<<<
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:
 */
            __pyx_t_36 = __pyx_v_i;
            if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_pybuffernd_minima_array.diminfo[0].shape;
            __pyx_v_minima_index = (*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.buf, __pyx_t_36, __pyx_pybuffernd_minima_array.diminfo[0].strides));

            /* "pyquant/cpeaks.pyx":456
 *                     for i in xrange(left, left_stop, -1):
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]             # <<<<<<<<<<<<<<
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:
 *                             if i == left:
 */
            __pyx_t_37 = __pyx_v_minima_index;
            if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_pybuffernd_ydata_peaks.diminfo[0].shape;
            __pyx_v_minima_value = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.buf, __pyx_t_37, __pyx_pybuffernd_ydata_peaks.diminfo[0].strides));

            /* "pyquant/cpeaks.pyx":457
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:             # <<<<<<<<<<<<<<
 *                             if i == left:
 *                                 left = minima_index
 */
            __pyx_t_17 = ((__pyx_v_minima_value > __pyx_v_rel_peak) != 0);
            if (!__pyx_t_17) {
            } else {
              __pyx_t_10 = __pyx_t_17;
              goto __pyx_L60_bool_binop_done;
            }
            __pyx_t_17 = ((__pyx_v_minima_value < (__pyx_v_rel_peak * 0.1)) != 0);
            if (!__pyx_t_17) {
            } else {
              __pyx_t_10 = __pyx_t_17;
              goto __pyx_L60_bool_binop_done;
            }
            __pyx_t_38 = (__pyx_v_minima_index - 1);
            if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_pybuffernd_ydata_peaks.diminfo[0].shape;
            __pyx_t_17 = ((((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.buf, __pyx_t_38, __pyx_pybuffernd_ydata_peaks.diminfo[0].strides)) * 0.9) > __pyx_v_minima_value) != 0);
            __pyx_t_10 = __pyx_t_17;
            __pyx_L60_bool_binop_done:;
            if (__pyx_t_10) {

              /* "pyquant/cpeaks.pyx":458
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:
 *                             if i == left:             # <<<<<<<<<<<<<<
 *                                 left = minima_index
 *                             break
 */
              __pyx_t_10 = ((__pyx_v_i == __pyx_v_left) != 0);
              if (__pyx_t_10) {

                /* "pyquant/cpeaks.pyx":459
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:
 *                             if i == left:
 *                                 left = minima_index             # <<<<<<<<<<<<<<
 *                             break
 *                         left = minima_index
 */
                __pyx_v_left = __pyx_v_minima_index;

                /* "pyquant/cpeaks.pyx":458
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:
 *                             if i == left:             # <<<<<<<<<<<<<<
 *                                 left = minima_index
 *                             break
 */
              }

              /* "pyquant/cpeaks.pyx":460
 *                             if i == left:
 *                                 left = minima_index
 *                             break             # <<<<<<<<<<<<<<
 *                         left = minima_index
 *                 last_peak = peak_index
 */
              goto __pyx_L58_break;

              /* "pyquant/cpeaks.pyx":457
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or ydata_peaks[minima_index-1]*0.9>minima_value:             # <<<<<<<<<<<<<<
 *                             if i == left:
 *                                 left = minima_index
 */
            }

            /* "pyquant/cpeaks.pyx":461
 *                                 left = minima_index
 *                             break
 *                         left = minima_index             # <<<<<<<<<<<<<<
 *                 last_peak = peak_index
 *                 right = np.searchsorted(minima_array, peak_index)
 */
            __pyx_v_left = __pyx_v_minima_index;
          }
          __pyx_L58_break:;
        }
        __pyx_L55:;

        /* "pyquant/cpeaks.pyx":462
 *                             break
 *                         left = minima_index
 *                 last_peak = peak_index             # <<<<<<<<<<<<<<
 *                 right = np.searchsorted(minima_array, peak_index)
 *                 right_stop = np.searchsorted(minima_array, next_peak)
 */
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_peak_index); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 462, __pyx_L1_error)
        __pyx_v_last_peak = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":463
 *                         left = minima_index
 *                 last_peak = peak_index
 *                 right = np.searchsorted(minima_array, peak_index)             # <<<<<<<<<<<<<<
 *                 right_stop = np.searchsorted(minima_array, next_peak)
 *                 if False and right == right_stop:
 */
        __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        __pyx_t_33 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_34))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_34);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_34);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_34, function);
            __pyx_t_33 = 1;
          }
        }
        __pyx_t_2 = PyTuple_New(2+__pyx_t_33); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_13) {
          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_13); __pyx_t_13 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_minima_array));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_minima_array));
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_33, ((PyObject *)__pyx_v_minima_array));
        __Pyx_INCREF(__pyx_v_peak_index);
        __Pyx_GIVEREF(__pyx_v_peak_index);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_33, __pyx_v_peak_index);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_34, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_right = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":464
 *                 last_peak = peak_index
 *                 right = np.searchsorted(minima_array, peak_index)
 *                 right_stop = np.searchsorted(minima_array, next_peak)             # <<<<<<<<<<<<<<
 *                 if False and right == right_stop:
 *                     right = minima_array[right]
 */
        __pyx_t_34 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_34, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        __pyx_t_34 = __Pyx_PyInt_From_int(__pyx_v_next_peak); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __pyx_t_13 = NULL;
        __pyx_t_33 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_33 = 1;
          }
        }
        __pyx_t_9 = PyTuple_New(2+__pyx_t_33); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_13) {
          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_13); __pyx_t_13 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_minima_array));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_minima_array));
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_33, ((PyObject *)__pyx_v_minima_array));
        __Pyx_GIVEREF(__pyx_t_34);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_33, __pyx_t_34);
        __pyx_t_34 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 464, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_right_stop = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":468
 *                     right = minima_array[right]
 *                 else:
 *                     for i in xrange(right, right_stop):             # <<<<<<<<<<<<<<
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 */
        __pyx_t_5 = __pyx_v_right_stop;
        for (__pyx_t_23 = __pyx_v_right; __pyx_t_23 < __pyx_t_5; __pyx_t_23+=1) {
          __pyx_v_i = __pyx_t_23;

          /* "pyquant/cpeaks.pyx":469
 *                 else:
 *                     for i in xrange(right, right_stop):
 *                         minima_index = minima_array[i]             # <<<<<<<<<<<<<<
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):
 */
          __pyx_t_39 = __pyx_v_i;
          if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_pybuffernd_minima_array.diminfo[0].shape;
          __pyx_v_minima_index = (*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.buf, __pyx_t_39, __pyx_pybuffernd_minima_array.diminfo[0].strides));

          /* "pyquant/cpeaks.pyx":470
 *                     for i in xrange(right, right_stop):
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]             # <<<<<<<<<<<<<<
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):
 *                             if i == right:
 */
          __pyx_t_40 = __pyx_v_minima_index;
          if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_pybuffernd_ydata_peaks.diminfo[0].shape;
          __pyx_v_minima_value = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.buf, __pyx_t_40, __pyx_pybuffernd_ydata_peaks.diminfo[0].strides));

          /* "pyquant/cpeaks.pyx":471
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):             # <<<<<<<<<<<<<<
 *                             if i == right:
 *                                 right = minima_index
 */
          __pyx_t_17 = ((__pyx_v_minima_value > __pyx_v_rel_peak) != 0);
          if (!__pyx_t_17) {
          } else {
            __pyx_t_10 = __pyx_t_17;
            goto __pyx_L67_bool_binop_done;
          }
          __pyx_t_17 = ((__pyx_v_minima_value < (__pyx_v_rel_peak * 0.1)) != 0);
          if (!__pyx_t_17) {
          } else {
            __pyx_t_10 = __pyx_t_17;
            goto __pyx_L67_bool_binop_done;
          }
          __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_minima_index + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 471, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_ydata_peaks), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 471, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_9 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 471, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 471, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (__pyx_t_17) {
          } else {
            __pyx_t_10 = __pyx_t_17;
            goto __pyx_L67_bool_binop_done;
          }
          __pyx_t_41 = (__pyx_v_minima_index + 1);
          if (__pyx_t_41 < 0) __pyx_t_41 += __pyx_pybuffernd_ydata_peaks.diminfo[0].shape;
          __pyx_t_17 = ((((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer.buf, __pyx_t_41, __pyx_pybuffernd_ydata_peaks.diminfo[0].strides)) * 0.9) > __pyx_v_minima_value) != 0);
          __pyx_t_10 = __pyx_t_17;
          __pyx_L67_bool_binop_done:;
          if (__pyx_t_10) {

            /* "pyquant/cpeaks.pyx":472
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):
 *                             if i == right:             # <<<<<<<<<<<<<<
 *                                 right = minima_index
 *                             break
 */
            __pyx_t_10 = ((__pyx_v_i == __pyx_v_right) != 0);
            if (__pyx_t_10) {

              /* "pyquant/cpeaks.pyx":473
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):
 *                             if i == right:
 *                                 right = minima_index             # <<<<<<<<<<<<<<
 *                             break
 *                         right = minima_index
 */
              __pyx_v_right = __pyx_v_minima_index;

              /* "pyquant/cpeaks.pyx":472
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):
 *                             if i == right:             # <<<<<<<<<<<<<<
 *                                 right = minima_index
 *                             break
 */
            }

            /* "pyquant/cpeaks.pyx":474
 *                             if i == right:
 *                                 right = minima_index
 *                             break             # <<<<<<<<<<<<<<
 *                         right = minima_index
 *                 if right >= minima_array[-1]:
 */
            goto __pyx_L65_break;

            /* "pyquant/cpeaks.pyx":471
 *                         minima_index = minima_array[i]
 *                         minima_value = ydata_peaks[minima_index]
 *                         if minima_value > rel_peak or minima_value < rel_peak*0.1 or (minima_index+1 < ydata_peaks.size and ydata_peaks[minima_index+1]*0.9>minima_value):             # <<<<<<<<<<<<<<
 *                             if i == right:
 *                                 right = minima_index
 */
          }

          /* "pyquant/cpeaks.pyx":475
 *                                 right = minima_index
 *                             break
 *                         right = minima_index             # <<<<<<<<<<<<<<
 *                 if right >= minima_array[-1]:
 *                     right = minima_array[-1]
 */
          __pyx_v_right = __pyx_v_minima_index;
        }
        __pyx_L65_break:;

        /* "pyquant/cpeaks.pyx":476
 *                             break
 *                         right = minima_index
 *                 if right >= minima_array[-1]:             # <<<<<<<<<<<<<<
 *                     right = minima_array[-1]
 *                 if right > next_peak:
 */
        __pyx_t_42 = -1L;
        if (__pyx_t_42 < 0) __pyx_t_42 += __pyx_pybuffernd_minima_array.diminfo[0].shape;
        __pyx_t_10 = ((__pyx_v_right >= (*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.buf, __pyx_t_42, __pyx_pybuffernd_minima_array.diminfo[0].strides))) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":477
 *                         right = minima_index
 *                 if right >= minima_array[-1]:
 *                     right = minima_array[-1]             # <<<<<<<<<<<<<<
 *                 if right > next_peak:
 *                     right = next_peak
 */
          __pyx_t_43 = -1L;
          if (__pyx_t_43 < 0) __pyx_t_43 += __pyx_pybuffernd_minima_array.diminfo[0].shape;
          __pyx_v_right = (*__Pyx_BufPtrStrided1d(long *, __pyx_pybuffernd_minima_array.rcbuffer->pybuffer.buf, __pyx_t_43, __pyx_pybuffernd_minima_array.diminfo[0].strides));

          /* "pyquant/cpeaks.pyx":476
 *                             break
 *                         right = minima_index
 *                 if right >= minima_array[-1]:             # <<<<<<<<<<<<<<
 *                     right = minima_array[-1]
 *                 if right > next_peak:
 */
        }

        /* "pyquant/cpeaks.pyx":478
 *                 if right >= minima_array[-1]:
 *                     right = minima_array[-1]
 *                 if right > next_peak:             # <<<<<<<<<<<<<<
 *                     right = next_peak
 *                 if right < peak_index:
 */
        __pyx_t_10 = ((__pyx_v_right > __pyx_v_next_peak) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":479
 *                     right = minima_array[-1]
 *                 if right > next_peak:
 *                     right = next_peak             # <<<<<<<<<<<<<<
 *                 if right < peak_index:
 *                     right = next_peak
 */
          __pyx_v_right = __pyx_v_next_peak;

          /* "pyquant/cpeaks.pyx":478
 *                 if right >= minima_array[-1]:
 *                     right = minima_array[-1]
 *                 if right > next_peak:             # <<<<<<<<<<<<<<
 *                     right = next_peak
 *                 if right < peak_index:
 */
        }

        /* "pyquant/cpeaks.pyx":480
 *                 if right > next_peak:
 *                     right = next_peak
 *                 if right < peak_index:             # <<<<<<<<<<<<<<
 *                     right = next_peak
 *                 if right >= len(xdata):
 */
        __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_right); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 480, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_9, __pyx_v_peak_index, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 480, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 480, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":481
 *                     right = next_peak
 *                 if right < peak_index:
 *                     right = next_peak             # <<<<<<<<<<<<<<
 *                 if right >= len(xdata):
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 */
          __pyx_v_right = __pyx_v_next_peak;

          /* "pyquant/cpeaks.pyx":480
 *                 if right > next_peak:
 *                     right = next_peak
 *                 if right < peak_index:             # <<<<<<<<<<<<<<
 *                     right = next_peak
 *                 if right >= len(xdata):
 */
        }

        /* "pyquant/cpeaks.pyx":482
 *                 if right < peak_index:
 *                     right = next_peak
 *                 if right >= len(xdata):             # <<<<<<<<<<<<<<
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 else:
 */
        __pyx_t_33 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_33 == -1)) __PYX_ERR(0, 482, __pyx_L1_error)
        __pyx_t_10 = ((__pyx_v_right >= __pyx_t_33) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":483
 *                     right = next_peak
 *                 if right >= len(xdata):
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *                 else:
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[right]), (min_spacing, peak_range)])
 */
          __pyx_t_2 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
          __Pyx_INCREF(__pyx_float_1_01);
          __Pyx_GIVEREF(__pyx_float_1_01);
          PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_float_1_01);
          __pyx_t_2 = 0;
          __pyx_t_44 = __pyx_v_left;
          if (__pyx_t_44 < 0) __pyx_t_44 += __pyx_pybuffernd_xdata.diminfo[0].shape;
          __pyx_t_2 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_44, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_45 = -1L;
          if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_pybuffernd_xdata.diminfo[0].shape;
          __pyx_t_3 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_45, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_34 = PyTuple_New(2); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_34, 1, __pyx_t_3);
          __pyx_t_2 = 0;
          __pyx_t_3 = 0;
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_INCREF(__pyx_v_min_spacing);
          __Pyx_GIVEREF(__pyx_v_min_spacing);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_min_spacing);
          __Pyx_INCREF(__pyx_v_peak_range);
          __Pyx_GIVEREF(__pyx_v_peak_range);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_peak_range);
          __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_34);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_34);
          __Pyx_GIVEREF(__pyx_t_3);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_3);
          __pyx_t_9 = 0;
          __pyx_t_34 = 0;
          __pyx_t_3 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_bnds, __pyx_t_2); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 483, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":482
 *                 if right < peak_index:
 *                     right = next_peak
 *                 if right >= len(xdata):             # <<<<<<<<<<<<<<
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 else:
 */
          goto __pyx_L75;
        }

        /* "pyquant/cpeaks.pyx":485
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 else:
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[right]), (min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])
 */
        /*else*/ {
          __pyx_t_2 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
          __Pyx_INCREF(__pyx_float_1_01);
          __Pyx_GIVEREF(__pyx_float_1_01);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_float_1_01);
          __pyx_t_2 = 0;
          __pyx_t_46 = __pyx_v_left;
          if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_pybuffernd_xdata.diminfo[0].shape;
          __pyx_t_2 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_46, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_47 = __pyx_v_right;
          if (__pyx_t_47 < 0) __pyx_t_47 += __pyx_pybuffernd_xdata.diminfo[0].shape;
          __pyx_t_34 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_47, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_34);
          PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_34);
          __pyx_t_2 = 0;
          __pyx_t_34 = 0;
          __pyx_t_34 = PyTuple_New(2); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __Pyx_INCREF(__pyx_v_min_spacing);
          __Pyx_GIVEREF(__pyx_v_min_spacing);
          PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_v_min_spacing);
          __Pyx_INCREF(__pyx_v_peak_range);
          __Pyx_GIVEREF(__pyx_v_peak_range);
          PyTuple_SET_ITEM(__pyx_t_34, 1, __pyx_v_peak_range);
          __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_3);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_34);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_34);
          __pyx_t_3 = 0;
          __pyx_t_9 = 0;
          __pyx_t_34 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_bnds, __pyx_t_2); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 485, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __pyx_L75:;

        /* "pyquant/cpeaks.pyx":486
 *                 else:
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[right]), (min_spacing, peak_range)])
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 */
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 486, __pyx_L1_error)
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":487
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[right]), (min_spacing, peak_range)])
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *                 peak_values = ydata[left:right]
 *                 peak_indices = xdata[left:right]
 */
          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 487, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_v_min_spacing);
          __Pyx_GIVEREF(__pyx_v_min_spacing);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_min_spacing);
          __Pyx_INCREF(__pyx_v_peak_range);
          __Pyx_GIVEREF(__pyx_v_peak_range);
          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_peak_range);
          __pyx_t_34 = PyList_New(1); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 487, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_34, 0, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_bnds, __pyx_t_34); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 487, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;

          /* "pyquant/cpeaks.pyx":486
 *                 else:
 *                     bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[right]), (min_spacing, peak_range)])
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 */
        }

        /* "pyquant/cpeaks.pyx":488
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]             # <<<<<<<<<<<<<<
 *                 peak_indices = xdata[left:right]
 *             else:
 */
        __pyx_t_34 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 488, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        if (!(likely(((__pyx_t_34) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_34, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 488, __pyx_L1_error)
        __pyx_t_4 = ((PyArrayObject *)__pyx_t_34);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer);
          __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_5 < 0)) {
            PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer, (PyObject*)__pyx_v_peak_values, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
            }
          }
          __pyx_pybuffernd_peak_values.diminfo[0].strides = __pyx_pybuffernd_peak_values.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_peak_values.diminfo[0].shape = __pyx_pybuffernd_peak_values.rcbuffer->pybuffer.shape[0];
          if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 488, __pyx_L1_error)
        }
        __pyx_t_4 = 0;
        __Pyx_XDECREF_SET(__pyx_v_peak_values, ((PyArrayObject *)__pyx_t_34));
        __pyx_t_34 = 0;

        /* "pyquant/cpeaks.pyx":489
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 *                 peak_indices = xdata[left:right]             # <<<<<<<<<<<<<<
 *             else:
 *                 left = 0
 */
        __pyx_t_34 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 489, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        if (!(likely(((__pyx_t_34) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_34, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 489, __pyx_L1_error)
        __pyx_t_4 = ((PyArrayObject *)__pyx_t_34);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer);
          __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_5 < 0)) {
            PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer, (PyObject*)__pyx_v_peak_indices, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
            }
          }
          __pyx_pybuffernd_peak_indices.diminfo[0].strides = __pyx_pybuffernd_peak_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_peak_indices.diminfo[0].shape = __pyx_pybuffernd_peak_indices.rcbuffer->pybuffer.shape[0];
          if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 489, __pyx_L1_error)
        }
        __pyx_t_4 = 0;
        __Pyx_XDECREF_SET(__pyx_v_peak_indices, ((PyArrayObject *)__pyx_t_34));
        __pyx_t_34 = 0;

        /* "pyquant/cpeaks.pyx":443
 *             rel_peak = ydata_peaks[peak_index]
 *             # find the points around it to estimate the std of the peak
 *             if minima_array.size:             # <<<<<<<<<<<<<<
 *                 left = np.searchsorted(minima_array, peak_index)-1
 *                 left_stop = np.searchsorted(minima_array, last_peak) if last_peak != -1 else -1
 */
        goto __pyx_L54;
      }

      /* "pyquant/cpeaks.pyx":491
 *                 peak_indices = xdata[left:right]
 *             else:
 *                 left = 0             # <<<<<<<<<<<<<<
 *                 right = len(xdata)
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 */
      /*else*/ {
        __pyx_v_left = 0;

        /* "pyquant/cpeaks.pyx":492
 *             else:
 *                 left = 0
 *                 right = len(xdata)             # <<<<<<<<<<<<<<
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 if bigauss_fit:
 */
        __pyx_t_33 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_33 == -1)) __PYX_ERR(0, 492, __pyx_L1_error)
        __pyx_v_right = __pyx_t_33;

        /* "pyquant/cpeaks.pyx":493
 *                 left = 0
 *                 right = len(xdata)
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])
 */
        __pyx_t_34 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_34);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_34);
        __Pyx_INCREF(__pyx_float_1_01);
        __Pyx_GIVEREF(__pyx_float_1_01);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_float_1_01);
        __pyx_t_34 = 0;
        __pyx_t_48 = __pyx_v_left;
        if (__pyx_t_48 < 0) __pyx_t_48 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        __pyx_t_34 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_48, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __pyx_t_49 = -1L;
        if (__pyx_t_49 < 0) __pyx_t_49 += __pyx_pybuffernd_xdata.diminfo[0].shape;
        __pyx_t_9 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_xdata.rcbuffer->pybuffer.buf, __pyx_t_49, __pyx_pybuffernd_xdata.diminfo[0].strides))); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_34);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_34);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9);
        __pyx_t_34 = 0;
        __pyx_t_9 = 0;
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_v_min_spacing);
        __Pyx_GIVEREF(__pyx_v_min_spacing);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_min_spacing);
        __Pyx_INCREF(__pyx_v_peak_range);
        __Pyx_GIVEREF(__pyx_v_peak_range);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_peak_range);
        __pyx_t_34 = PyList_New(3); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __Pyx_GIVEREF(__pyx_t_2);
        PyList_SET_ITEM(__pyx_t_34, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_3);
        PyList_SET_ITEM(__pyx_t_34, 1, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_9);
        PyList_SET_ITEM(__pyx_t_34, 2, __pyx_t_9);
        __pyx_t_2 = 0;
        __pyx_t_3 = 0;
        __pyx_t_9 = 0;
        __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_bnds, __pyx_t_34); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;

        /* "pyquant/cpeaks.pyx":494
 *                 right = len(xdata)
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 */
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 494, __pyx_L1_error)
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":495
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])             # <<<<<<<<<<<<<<
 *                 peak_values = ydata[left:right]
 *                 peak_indices = xdata[left:right]
 */
          __pyx_t_34 = PyTuple_New(2); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __Pyx_INCREF(__pyx_v_min_spacing);
          __Pyx_GIVEREF(__pyx_v_min_spacing);
          PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_v_min_spacing);
          __Pyx_INCREF(__pyx_v_peak_range);
          __Pyx_GIVEREF(__pyx_v_peak_range);
          PyTuple_SET_ITEM(__pyx_t_34, 1, __pyx_v_peak_range);
          __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_34);
          PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_34);
          __pyx_t_34 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_bnds, __pyx_t_9); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "pyquant/cpeaks.pyx":494
 *                 right = len(xdata)
 *                 bnds.extend([(rel_peak, 1.01), (xdata[left], xdata[-1]), (min_spacing, peak_range)])
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 */
        }

        /* "pyquant/cpeaks.pyx":496
 *                 if bigauss_fit:
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]             # <<<<<<<<<<<<<<
 *                 peak_indices = xdata[left:right]
 * 
 */
        __pyx_t_9 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 496, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 496, __pyx_L1_error)
        __pyx_t_4 = ((PyArrayObject *)__pyx_t_9);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer);
          __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_5 < 0)) {
            PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer, (PyObject*)__pyx_v_peak_values, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
            }
          }
          __pyx_pybuffernd_peak_values.diminfo[0].strides = __pyx_pybuffernd_peak_values.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_peak_values.diminfo[0].shape = __pyx_pybuffernd_peak_values.rcbuffer->pybuffer.shape[0];
          if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 496, __pyx_L1_error)
        }
        __pyx_t_4 = 0;
        __Pyx_XDECREF_SET(__pyx_v_peak_values, ((PyArrayObject *)__pyx_t_9));
        __pyx_t_9 = 0;

        /* "pyquant/cpeaks.pyx":497
 *                     bnds.extend([(min_spacing, peak_range)])
 *                 peak_values = ydata[left:right]
 *                 peak_indices = xdata[left:right]             # <<<<<<<<<<<<<<
 * 
 *             if debug:
 */
        __pyx_t_9 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 497, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 497, __pyx_L1_error)
        __pyx_t_4 = ((PyArrayObject *)__pyx_t_9);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer);
          __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_5 < 0)) {
            PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer, (PyObject*)__pyx_v_peak_indices, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8);
            }
          }
          __pyx_pybuffernd_peak_indices.diminfo[0].strides = __pyx_pybuffernd_peak_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_peak_indices.diminfo[0].shape = __pyx_pybuffernd_peak_indices.rcbuffer->pybuffer.shape[0];
          if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 497, __pyx_L1_error)
        }
        __pyx_t_4 = 0;
        __Pyx_XDECREF_SET(__pyx_v_peak_indices, ((PyArrayObject *)__pyx_t_9));
        __pyx_t_9 = 0;
      }
      __pyx_L54:;

      /* "pyquant/cpeaks.pyx":499
 *                 peak_indices = xdata[left:right]
 * 
 *             if debug:             # <<<<<<<<<<<<<<
 *                 pass
 *                 #print('bounds', peak_index, left, right, peak_values.tolist(), peak_indices.tolist(), bnds)
 */
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 499, __pyx_L1_error)
      if (__pyx_t_10) {
      }

      /* "pyquant/cpeaks.pyx":503
 *                 #print('bounds', peak_index, left, right, peak_values.tolist(), peak_indices.tolist(), bnds)
 * 
 *             if peak_values.any():             # <<<<<<<<<<<<<<
 *                 average = np.average(peak_indices, weights=peak_values)
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))
 */
      __pyx_t_34 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_peak_values), __pyx_n_s_any); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 503, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_34);
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_34))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_34);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_34);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_34, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_34, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 503, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_34); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 503, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 503, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":504
 * 
 *             if peak_values.any():
 *                 average = np.average(peak_indices, weights=peak_values)             # <<<<<<<<<<<<<<
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))
 *                 if variance == 0:
 */
        __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_average); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_INCREF(((PyObject *)__pyx_v_peak_indices));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_peak_indices));
        PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_v_peak_indices));
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_weights, ((PyObject *)__pyx_v_peak_values)) < 0) __PYX_ERR(0, 504, __pyx_L1_error)
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_34, __pyx_t_9, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 504, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_average = __pyx_t_12;

        /* "pyquant/cpeaks.pyx":505
 *             if peak_values.any():
 *                 average = np.average(peak_indices, weights=peak_values)
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))             # <<<<<<<<<<<<<<
 *                 if variance == 0:
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 */
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_average); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_13 = PyNumber_Subtract(((PyObject *)__pyx_v_peak_indices), __pyx_t_3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyNumber_Power(__pyx_t_13, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_weights, ((PyObject *)__pyx_v_peak_values)) < 0) __PYX_ERR(0, 505, __pyx_L1_error)
        __pyx_t_50 = __Pyx_PyObject_Call(__pyx_t_34, __pyx_t_13, __pyx_t_3); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
          }
        }
        if (!__pyx_t_3) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_50); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 505, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3); __pyx_t_3 = NULL;
          __Pyx_GIVEREF(__pyx_t_50);
          PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_50);
          __pyx_t_50 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 505, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_variance = __pyx_t_12;

        /* "pyquant/cpeaks.pyx":506
 *                 average = np.average(peak_indices, weights=peak_values)
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))
 *                 if variance == 0:             # <<<<<<<<<<<<<<
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *                     if peak_index >= 1:
 */
        __pyx_t_10 = ((__pyx_v_variance == 0.0) != 0);
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":508
 *                 if variance == 0:
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *                     if peak_index >= 1:             # <<<<<<<<<<<<<<
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])
 *                     elif peak_index < len(xdata):
 */
          __pyx_t_2 = PyObject_RichCompare(__pyx_v_peak_index, __pyx_int_1, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error)
          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (__pyx_t_10) {

            /* "pyquant/cpeaks.pyx":509
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *                     if peak_index >= 1:
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])             # <<<<<<<<<<<<<<
 *                     elif peak_index < len(xdata):
 *                         variance = np.abs(xdata[peak_index+1]-xdata[peak_index])
 */
            __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_abs); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_9 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_peak_index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_50 = __Pyx_PyInt_SubtractObjC(__pyx_v_peak_index, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_50);
            __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_t_50); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
            __pyx_t_50 = PyNumber_Subtract(__pyx_t_9, __pyx_t_3); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_50);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_3 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_13);
              if (likely(__pyx_t_3)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                __Pyx_INCREF(__pyx_t_3);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_13, function);
              }
            }
            if (!__pyx_t_3) {
              __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_50); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
              __Pyx_GOTREF(__pyx_t_2);
            } else {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 509, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL;
              __Pyx_GIVEREF(__pyx_t_50);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_50);
              __pyx_t_50 = 0;
              __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 509, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_v_variance = __pyx_t_12;

            /* "pyquant/cpeaks.pyx":508
 *                 if variance == 0:
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *                     if peak_index >= 1:             # <<<<<<<<<<<<<<
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])
 *                     elif peak_index < len(xdata):
 */
            goto __pyx_L81;
          }

          /* "pyquant/cpeaks.pyx":510
 *                     if peak_index >= 1:
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])
 *                     elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *                         variance = np.abs(xdata[peak_index+1]-xdata[peak_index])
 *                     else:
 */
          __pyx_t_33 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_33 == -1)) __PYX_ERR(0, 510, __pyx_L1_error)
          __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_33); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 510, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_13 = PyObject_RichCompare(__pyx_v_peak_index, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_13); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 510, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 510, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (__pyx_t_10) {

            /* "pyquant/cpeaks.pyx":511
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])
 *                     elif peak_index < len(xdata):
 *                         variance = np.abs(xdata[peak_index+1]-xdata[peak_index])             # <<<<<<<<<<<<<<
 *                     else:
 *                         # we have only 1 data point, most RT's fall into this width
 */
            __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_abs); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_peak_index, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_50 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_t_2); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_50);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_peak_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_3 = PyNumber_Subtract(__pyx_t_50, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_t_2 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && 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_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 511, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_13);
            } else {
              __pyx_t_50 = PyTuple_New(1+1); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 511, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_50);
              __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_50, 0, __pyx_t_2); __pyx_t_2 = NULL;
              __Pyx_GIVEREF(__pyx_t_3);
              PyTuple_SET_ITEM(__pyx_t_50, 0+1, __pyx_t_3);
              __pyx_t_3 = 0;
              __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_50, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 511, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
            }
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_13); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 511, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __pyx_v_variance = __pyx_t_12;

            /* "pyquant/cpeaks.pyx":510
 *                     if peak_index >= 1:
 *                         variance = np.abs(xdata[peak_index]-xdata[peak_index-1])
 *                     elif peak_index < len(xdata):             # <<<<<<<<<<<<<<
 *                         variance = np.abs(xdata[peak_index+1]-xdata[peak_index])
 *                     else:
 */
            goto __pyx_L81;
          }

          /* "pyquant/cpeaks.pyx":514
 *                     else:
 *                         # we have only 1 data point, most RT's fall into this width
 *                         variance = 0.05             # <<<<<<<<<<<<<<
 *             else:
 *                 variance = 0.05
 */
          /*else*/ {
            __pyx_v_variance = 0.05;
          }
          __pyx_L81:;

          /* "pyquant/cpeaks.pyx":506
 *                 average = np.average(peak_indices, weights=peak_values)
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))
 *                 if variance == 0:             # <<<<<<<<<<<<<<
 *                     # we have a singular peak if variance == 0, so set the variance to half of the x/y spacing
 *                     if peak_index >= 1:
 */
        }

        /* "pyquant/cpeaks.pyx":503
 *                 #print('bounds', peak_index, left, right, peak_values.tolist(), peak_indices.tolist(), bnds)
 * 
 *             if peak_values.any():             # <<<<<<<<<<<<<<
 *                 average = np.average(peak_indices, weights=peak_values)
 *                 variance = np.sqrt(np.average((peak_indices-average)**2, weights=peak_values))
 */
        goto __pyx_L79;
      }

      /* "pyquant/cpeaks.pyx":516
 *                         variance = 0.05
 *             else:
 *                 variance = 0.05             # <<<<<<<<<<<<<<
 *                 average = xdata[peak_index]
 *             if variance is not None and variance < min_spacing:
 */
      /*else*/ {
        __pyx_v_variance = 0.05;

        /* "pyquant/cpeaks.pyx":517
 *             else:
 *                 variance = 0.05
 *                 average = xdata[peak_index]             # <<<<<<<<<<<<<<
 *             if variance is not None and variance < min_spacing:
 *                 variance = min_spacing
 */
        __pyx_t_13 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_peak_index); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 517, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_13); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 517, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_v_average = __pyx_t_12;
      }
      __pyx_L79:;

      /* "pyquant/cpeaks.pyx":518
 *                 variance = 0.05
 *                 average = xdata[peak_index]
 *             if variance is not None and variance < min_spacing:             # <<<<<<<<<<<<<<
 *                 variance = min_spacing
 *             if variance is not None:
 */
      __pyx_t_13 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_17 = (__pyx_t_13 != Py_None);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_19 = (__pyx_t_17 != 0);
      if (__pyx_t_19) {
      } else {
        __pyx_t_10 = __pyx_t_19;
        goto __pyx_L83_bool_binop_done;
      }
      __pyx_t_13 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_9 = PyObject_RichCompare(__pyx_t_13, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_10 = __pyx_t_19;
      __pyx_L83_bool_binop_done:;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":519
 *                 average = xdata[peak_index]
 *             if variance is not None and variance < min_spacing:
 *                 variance = min_spacing             # <<<<<<<<<<<<<<
 *             if variance is not None:
 *                 if bigauss_fit:
 */
        __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_v_min_spacing); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 519, __pyx_L1_error)
        __pyx_v_variance = __pyx_t_12;

        /* "pyquant/cpeaks.pyx":518
 *                 variance = 0.05
 *                 average = xdata[peak_index]
 *             if variance is not None and variance < min_spacing:             # <<<<<<<<<<<<<<
 *                 variance = min_spacing
 *             if variance is not None:
 */
      }

      /* "pyquant/cpeaks.pyx":520
 *             if variance is not None and variance < min_spacing:
 *                 variance = min_spacing
 *             if variance is not None:             # <<<<<<<<<<<<<<
 *                 if bigauss_fit:
 *                     guess.extend([rel_peak, average, variance, variance])
 */
      __pyx_t_9 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_19 = (__pyx_t_10 != 0);
      if (__pyx_t_19) {

        /* "pyquant/cpeaks.pyx":521
 *                 variance = min_spacing
 *             if variance is not None:
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     guess.extend([rel_peak, average, variance, variance])
 *                 else:
 */
        __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 521, __pyx_L1_error)
        if (__pyx_t_19) {

          /* "pyquant/cpeaks.pyx":522
 *             if variance is not None:
 *                 if bigauss_fit:
 *                     guess.extend([rel_peak, average, variance, variance])             # <<<<<<<<<<<<<<
 *                 else:
 *                     guess.extend([rel_peak, average, variance])
 */
          __pyx_t_9 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_13 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_50 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_50);
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_13);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_50);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_50);
          __Pyx_GIVEREF(__pyx_t_3);
          PyList_SET_ITEM(__pyx_t_2, 3, __pyx_t_3);
          __pyx_t_9 = 0;
          __pyx_t_13 = 0;
          __pyx_t_50 = 0;
          __pyx_t_3 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_guess, __pyx_t_2); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":521
 *                 variance = min_spacing
 *             if variance is not None:
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     guess.extend([rel_peak, average, variance, variance])
 *                 else:
 */
          goto __pyx_L86;
        }

        /* "pyquant/cpeaks.pyx":524
 *                     guess.extend([rel_peak, average, variance, variance])
 *                 else:
 *                     guess.extend([rel_peak, average, variance])             # <<<<<<<<<<<<<<
 *         if not guess:
 *             average = np.average(xdata, weights=ydata)
 */
        /*else*/ {
          __pyx_t_2 = PyFloat_FromDouble(__pyx_v_rel_peak); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 524, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_50 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 524, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_50);
          __pyx_t_13 = PyList_New(3); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 524, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_13, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_3);
          PyList_SET_ITEM(__pyx_t_13, 1, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_50);
          PyList_SET_ITEM(__pyx_t_13, 2, __pyx_t_50);
          __pyx_t_2 = 0;
          __pyx_t_3 = 0;
          __pyx_t_50 = 0;
          __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_guess, __pyx_t_13); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 524, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }
        __pyx_L86:;

        /* "pyquant/cpeaks.pyx":520
 *             if variance is not None and variance < min_spacing:
 *                 variance = min_spacing
 *             if variance is not None:             # <<<<<<<<<<<<<<
 *                 if bigauss_fit:
 *                     guess.extend([rel_peak, average, variance, variance])
 */
      }

      /* "pyquant/cpeaks.pyx":436
 *         skip_peaks = set([])
 *         fitted_peaks = []
 *         for peak_num, peak_index in enumerate(row_peaks):             # <<<<<<<<<<<<<<
 *             if peak_index in skip_peaks:
 *                 continue
 */
      __pyx_L51_continue:;
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":525
 *                 else:
 *                     guess.extend([rel_peak, average, variance])
 *         if not guess:             # <<<<<<<<<<<<<<
 *             average = np.average(xdata, weights=ydata)
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 */
    __pyx_t_19 = (__pyx_v_guess != Py_None) && (PyList_GET_SIZE(__pyx_v_guess) != 0);
    __pyx_t_10 = ((!__pyx_t_19) != 0);
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":526
 *                     guess.extend([rel_peak, average, variance])
 *         if not guess:
 *             average = np.average(xdata, weights=ydata)             # <<<<<<<<<<<<<<
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *             if variance == 0:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_average); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_xdata));
      __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 526, __pyx_L1_error)
      __pyx_t_50 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, __pyx_t_13); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_50); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_v_average = __pyx_t_12;

      /* "pyquant/cpeaks.pyx":527
 *         if not guess:
 *             average = np.average(xdata, weights=ydata)
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))             # <<<<<<<<<<<<<<
 *             if variance == 0:
 *                 variance = 0.05
 */
      __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_average); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_3 = PyNumber_Subtract(((PyObject *)__pyx_v_xdata), __pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = PyNumber_Power(__pyx_t_3, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13);
      __pyx_t_13 = 0;
      __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_weights, ((PyObject *)__pyx_v_ydata)) < 0) __PYX_ERR(0, 527, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, __pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (!__pyx_t_13) {
        __pyx_t_50 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 527, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_50);
      } else {
        __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); __pyx_t_13 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_50 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 527, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_50); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_v_variance = __pyx_t_12;

      /* "pyquant/cpeaks.pyx":528
 *             average = np.average(xdata, weights=ydata)
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *             if variance == 0:             # <<<<<<<<<<<<<<
 *                 variance = 0.05
 *             guess = [max(ydata), average, variance]
 */
      __pyx_t_10 = ((__pyx_v_variance == 0.0) != 0);
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":529
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *             if variance == 0:
 *                 variance = 0.05             # <<<<<<<<<<<<<<
 *             guess = [max(ydata), average, variance]
 *             if bigauss_fit:
 */
        __pyx_v_variance = 0.05;

        /* "pyquant/cpeaks.pyx":528
 *             average = np.average(xdata, weights=ydata)
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 *             if variance == 0:             # <<<<<<<<<<<<<<
 *                 variance = 0.05
 *             guess = [max(ydata), average, variance]
 */
      }

      /* "pyquant/cpeaks.pyx":530
 *             if variance == 0:
 *                 variance = 0.05
 *             guess = [max(ydata), average, variance]             # <<<<<<<<<<<<<<
 *             if bigauss_fit:
 *                 guess.extend([variance])
 */
      __pyx_t_50 = PyTuple_New(1); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
      PyTuple_SET_ITEM(__pyx_t_50, 0, ((PyObject *)__pyx_v_ydata));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_50, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_50 = PyFloat_FromDouble(__pyx_v_average); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_3 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_50);
      PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_50);
      __Pyx_GIVEREF(__pyx_t_3);
      PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_50 = 0;
      __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_guess, ((PyObject*)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":531
 *                 variance = 0.05
 *             guess = [max(ydata), average, variance]
 *             if bigauss_fit:             # <<<<<<<<<<<<<<
 *                 guess.extend([variance])
 * 
 */
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 531, __pyx_L1_error)
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":532
 *             guess = [max(ydata), average, variance]
 *             if bigauss_fit:
 *                 guess.extend([variance])             # <<<<<<<<<<<<<<
 * 
 *         args = (xdata, ydata)
 */
        __pyx_t_2 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 532, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_2);
        PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_guess, __pyx_t_3); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 532, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyquant/cpeaks.pyx":531
 *                 variance = 0.05
 *             guess = [max(ydata), average, variance]
 *             if bigauss_fit:             # <<<<<<<<<<<<<<
 *                 guess.extend([variance])
 * 
 */
      }

      /* "pyquant/cpeaks.pyx":525
 *                 else:
 *                     guess.extend([rel_peak, average, variance])
 *         if not guess:             # <<<<<<<<<<<<<<
 *             average = np.average(xdata, weights=ydata)
 *             variance = np.sqrt(np.average((xdata-average)**2, weights=ydata))
 */
    }

    /* "pyquant/cpeaks.pyx":534
 *                 guess.extend([variance])
 * 
 *         args = (xdata, ydata)             # <<<<<<<<<<<<<<
 *         opts = {'maxiter': 1000}
 *         fit_func = bigauss_func if bigauss_fit else gauss_func
 */
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_xdata));
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ydata));
    __Pyx_XDECREF_SET(__pyx_v_args, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":535
 * 
 *         args = (xdata, ydata)
 *         opts = {'maxiter': 1000}             # <<<<<<<<<<<<<<
 *         fit_func = bigauss_func if bigauss_fit else gauss_func
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']
 */
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_maxiter, __pyx_int_1000) < 0) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_opts, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":536
 *         args = (xdata, ydata)
 *         opts = {'maxiter': 1000}
 *         fit_func = bigauss_func if bigauss_fit else gauss_func             # <<<<<<<<<<<<<<
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']
 *         routine = routines.pop(0)
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 536, __pyx_L1_error)
    if (__pyx_t_10) {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_func); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 536, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    } else {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gauss_func); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 536, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    }
    __Pyx_XDECREF_SET(__pyx_v_fit_func, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":537
 *         opts = {'maxiter': 1000}
 *         fit_func = bigauss_func if bigauss_fit else gauss_func
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']             # <<<<<<<<<<<<<<
 *         routine = routines.pop(0)
 *         if len(bnds) == 0:
 */
    __pyx_t_3 = PyList_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_n_s_SLSQP);
    __Pyx_GIVEREF(__pyx_n_s_SLSQP);
    PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_SLSQP);
    __Pyx_INCREF(__pyx_n_s_TNC);
    __Pyx_GIVEREF(__pyx_n_s_TNC);
    PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_TNC);
    __Pyx_INCREF(__pyx_kp_s_L_BFGS_B);
    __Pyx_GIVEREF(__pyx_kp_s_L_BFGS_B);
    PyList_SET_ITEM(__pyx_t_3, 2, __pyx_kp_s_L_BFGS_B);
    __Pyx_XDECREF_SET(__pyx_v_routines, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":538
 *         fit_func = bigauss_func if bigauss_fit else gauss_func
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']
 *         routine = routines.pop(0)             # <<<<<<<<<<<<<<
 *         if len(bnds) == 0:
 *             bnds = deepcopy(initial_bounds)
 */
    __pyx_t_3 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 538, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_routine, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":539
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']
 *         routine = routines.pop(0)
 *         if len(bnds) == 0:             # <<<<<<<<<<<<<<
 *             bnds = deepcopy(initial_bounds)
 *         jacobian = bigauss_jac if bigauss_fit else gauss_jac
 */
    __pyx_t_30 = PyList_GET_SIZE(__pyx_v_bnds); if (unlikely(__pyx_t_30 == -1)) __PYX_ERR(0, 539, __pyx_L1_error)
    __pyx_t_10 = ((__pyx_t_30 == 0) != 0);
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":540
 *         routine = routines.pop(0)
 *         if len(bnds) == 0:
 *             bnds = deepcopy(initial_bounds)             # <<<<<<<<<<<<<<
 *         jacobian = bigauss_jac if bigauss_fit else gauss_jac
 *         if debug:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_deepcopy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_50 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_50 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_50)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_50);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_50) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_initial_bounds); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 540, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_50); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_50); __pyx_t_50 = NULL;
        __Pyx_INCREF(__pyx_v_initial_bounds);
        __Pyx_GIVEREF(__pyx_v_initial_bounds);
        PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_initial_bounds);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 540, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 540, __pyx_L1_error)
      __Pyx_DECREF_SET(__pyx_v_bnds, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":539
 *         routines = ['SLSQP', 'TNC', 'L-BFGS-B']
 *         routine = routines.pop(0)
 *         if len(bnds) == 0:             # <<<<<<<<<<<<<<
 *             bnds = deepcopy(initial_bounds)
 *         jacobian = bigauss_jac if bigauss_fit else gauss_jac
 */
    }

    /* "pyquant/cpeaks.pyx":541
 *         if len(bnds) == 0:
 *             bnds = deepcopy(initial_bounds)
 *         jacobian = bigauss_jac if bigauss_fit else gauss_jac             # <<<<<<<<<<<<<<
 *         if debug:
 *             pass
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 541, __pyx_L1_error)
    if (__pyx_t_10) {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_bigauss_jac); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 541, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    } else {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gauss_jac); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 541, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    }
    __Pyx_XDECREF_SET(__pyx_v_jacobian, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":542
 *             bnds = deepcopy(initial_bounds)
 *         jacobian = bigauss_jac if bigauss_fit else gauss_jac
 *         if debug:             # <<<<<<<<<<<<<<
 *             pass
 *             #print('guess and bnds', guess, bnds)
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
    if (__pyx_t_10) {
    }

    /* "pyquant/cpeaks.pyx":545
 *             pass
 *             #print('guess and bnds', guess, bnds)
 *         results = [optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian)]             # <<<<<<<<<<<<<<
 *         while not results[-1].success and routines:
 *             routine = routines.pop(0)
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_minimize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_fit_func);
    __Pyx_GIVEREF(__pyx_v_fit_func);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fit_func);
    __Pyx_INCREF(__pyx_v_guess);
    __Pyx_GIVEREF(__pyx_v_guess);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_guess);
    __Pyx_INCREF(__pyx_v_args);
    __Pyx_GIVEREF(__pyx_v_args);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_args);
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 545, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_bounds, __pyx_v_bnds) < 0) __PYX_ERR(0, 545, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 545, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_jac, __pyx_v_jacobian) < 0) __PYX_ERR(0, 545, __pyx_L1_error)
    __pyx_t_50 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_50);
    __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_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_50);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_50);
    __pyx_t_50 = 0;
    __Pyx_XDECREF_SET(__pyx_v_results, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":546
 *             #print('guess and bnds', guess, bnds)
 *         results = [optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian)]
 *         while not results[-1].success and routines:             # <<<<<<<<<<<<<<
 *             routine = routines.pop(0)
 *             results.append(optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian))
 */
    while (1) {
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_results, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_success); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_50); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_17 = ((!__pyx_t_19) != 0);
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L94_bool_binop_done;
      }
      __pyx_t_17 = (__pyx_v_routines != Py_None) && (PyList_GET_SIZE(__pyx_v_routines) != 0);
      __pyx_t_10 = __pyx_t_17;
      __pyx_L94_bool_binop_done:;
      if (!__pyx_t_10) break;

      /* "pyquant/cpeaks.pyx":547
 *         results = [optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian)]
 *         while not results[-1].success and routines:
 *             routine = routines.pop(0)             # <<<<<<<<<<<<<<
 *             results.append(optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian))
 *             # print routine, res[-1]
 */
      __pyx_t_50 = __Pyx_PyList_PopIndex(__pyx_v_routines, __pyx_int_0, 0, 1, Py_ssize_t, PyInt_FromSsize_t); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 547, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      if (!(likely(PyString_CheckExact(__pyx_t_50))||((__pyx_t_50) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_50)->tp_name), 0))) __PYX_ERR(0, 547, __pyx_L1_error)
      __Pyx_DECREF_SET(__pyx_v_routine, ((PyObject*)__pyx_t_50));
      __pyx_t_50 = 0;

      /* "pyquant/cpeaks.pyx":548
 *         while not results[-1].success and routines:
 *             routine = routines.pop(0)
 *             results.append(optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian))             # <<<<<<<<<<<<<<
 *             # print routine, res[-1]
 *         if results[-1].success:
 */
      __pyx_t_50 = __Pyx_GetModuleGlobalName(__pyx_n_s_optimize); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_50, __pyx_n_s_minimize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_50 = PyTuple_New(3); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_INCREF(__pyx_v_fit_func);
      __Pyx_GIVEREF(__pyx_v_fit_func);
      PyTuple_SET_ITEM(__pyx_t_50, 0, __pyx_v_fit_func);
      __Pyx_INCREF(__pyx_v_guess);
      __Pyx_GIVEREF(__pyx_v_guess);
      PyTuple_SET_ITEM(__pyx_t_50, 1, __pyx_v_guess);
      __Pyx_INCREF(__pyx_v_args);
      __Pyx_GIVEREF(__pyx_v_args);
      PyTuple_SET_ITEM(__pyx_t_50, 2, __pyx_v_args);
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_method, __pyx_v_routine) < 0) __PYX_ERR(0, 548, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_bounds, __pyx_v_bnds) < 0) __PYX_ERR(0, 548, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_options, __pyx_v_opts) < 0) __PYX_ERR(0, 548, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_jac, __pyx_v_jacobian) < 0) __PYX_ERR(0, 548, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_50, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_2); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 548, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }

    /* "pyquant/cpeaks.pyx":550
 *             results.append(optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian))
 *             # print routine, res[-1]
 *         if results[-1].success:             # <<<<<<<<<<<<<<
 *             res = results[-1]
 *         else:
 */
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_results, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 550, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_success); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 550, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 550, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":551
 *             # print routine, res[-1]
 *         if results[-1].success:
 *             res = results[-1]             # <<<<<<<<<<<<<<
 *         else:
 *             res = sorted(results, key=attrgetter('fun'))[0]
 */
      __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_results, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 551, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_res, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":550
 *             results.append(optimize.minimize(fit_func, guess, args, method=routine, bounds=bnds, options=opts, jac=jacobian))
 *             # print routine, res[-1]
 *         if results[-1].success:             # <<<<<<<<<<<<<<
 *             res = results[-1]
 *         else:
 */
      goto __pyx_L96;
    }

    /* "pyquant/cpeaks.pyx":553
 *             res = results[-1]
 *         else:
 *             res = sorted(results, key=attrgetter('fun'))[0]             # <<<<<<<<<<<<<<
 *         n = len(xdata)
 *         k = len(res.x)
 */
    /*else*/ {
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_results);
      __Pyx_GIVEREF(__pyx_v_results);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_results);
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_50 = __Pyx_GetModuleGlobalName(__pyx_n_s_attrgetter); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_50, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_1) < 0) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_res, __pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L96:;

    /* "pyquant/cpeaks.pyx":554
 *         else:
 *             res = sorted(results, key=attrgetter('fun'))[0]
 *         n = len(xdata)             # <<<<<<<<<<<<<<
 *         k = len(res.x)
 *         # this is actually incorrect, but works better...
 */
    __pyx_t_30 = PyObject_Length(((PyObject *)__pyx_v_xdata)); if (unlikely(__pyx_t_30 == -1)) __PYX_ERR(0, 554, __pyx_L1_error)
    __pyx_v_n = __pyx_t_30;

    /* "pyquant/cpeaks.pyx":555
 *             res = sorted(results, key=attrgetter('fun'))[0]
 *         n = len(xdata)
 *         k = len(res.x)             # <<<<<<<<<<<<<<
 *         # this is actually incorrect, but works better...
 *         # bic = n*np.log(res.fun/n)+k+np.log(n)
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 555, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_30 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_30 == -1)) __PYX_ERR(0, 555, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_k = __pyx_t_30;

    /* "pyquant/cpeaks.pyx":558
 *         # this is actually incorrect, but works better...
 *         # bic = n*np.log(res.fun/n)+k+np.log(n)
 *         if bigauss_fit:             # <<<<<<<<<<<<<<
 *             bic = 2*k+2*np.log(res.fun/n)
 *         else:
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 558, __pyx_L1_error)
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":559
 *         # bic = n*np.log(res.fun/n)+k+np.log(n)
 *         if bigauss_fit:
 *             bic = 2*k+2*np.log(res.fun/n)             # <<<<<<<<<<<<<<
 *         else:
 *             bic = res.fun
 */
      __pyx_t_2 = PyFloat_FromDouble((2.0 * __pyx_v_k)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_fun); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_13 = PyFloat_FromDouble(__pyx_v_n); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_14 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_50))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_50);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_50);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_50, function);
        }
      }
      if (!__pyx_t_13) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_50, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); __pyx_t_13 = NULL;
        __Pyx_GIVEREF(__pyx_t_14);
        PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_14);
        __pyx_t_14 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_50, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_50 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_50); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 559, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_bic = __pyx_t_12;

      /* "pyquant/cpeaks.pyx":558
 *         # this is actually incorrect, but works better...
 *         # bic = n*np.log(res.fun/n)+k+np.log(n)
 *         if bigauss_fit:             # <<<<<<<<<<<<<<
 *             bic = 2*k+2*np.log(res.fun/n)
 *         else:
 */
      goto __pyx_L97;
    }

    /* "pyquant/cpeaks.pyx":561
 *             bic = 2*k+2*np.log(res.fun/n)
 *         else:
 *             bic = res.fun             # <<<<<<<<<<<<<<
 *         res.bic = bic
 *         step_size = 4 if bigauss_fit else 3
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_fun); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 561, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 561, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_bic = __pyx_t_12;
    }
    __pyx_L97:;

    /* "pyquant/cpeaks.pyx":562
 *         else:
 *             bic = res.fun
 *         res.bic = bic             # <<<<<<<<<<<<<<
 *         step_size = 4 if bigauss_fit else 3
 *         for index, value in enumerate(res.x[2::step_size]):
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_bic); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_res, __pyx_n_s_bic, __pyx_t_1) < 0) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":563
 *             bic = res.fun
 *         res.bic = bic
 *         step_size = 4 if bigauss_fit else 3             # <<<<<<<<<<<<<<
 *         for index, value in enumerate(res.x[2::step_size]):
 *           if value < min_spacing:
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 563, __pyx_L1_error)
    if (__pyx_t_10) {
      __Pyx_INCREF(__pyx_int_4);
      __pyx_t_1 = __pyx_int_4;
    } else {
      __Pyx_INCREF(__pyx_int_3);
      __pyx_t_1 = __pyx_int_3;
    }
    __Pyx_XDECREF_SET(__pyx_v_step_size, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":564
 *         res.bic = bic
 *         step_size = 4 if bigauss_fit else 3
 *         for index, value in enumerate(res.x[2::step_size]):             # <<<<<<<<<<<<<<
 *           if value < min_spacing:
 *             res.x[2+index*step_size] = min_spacing
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_1 = __pyx_int_0;
    __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_50);
    __pyx_t_2 = PySlice_New(__pyx_int_2, Py_None, __pyx_v_step_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetItem(__pyx_t_50, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_30 = 0;
      __pyx_t_31 = NULL;
    } else {
      __pyx_t_30 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_31 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 564, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_31)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_30 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_30); __Pyx_INCREF(__pyx_t_3); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 564, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_30 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_30); __Pyx_INCREF(__pyx_t_3); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 564, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_31(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          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, 564, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_1);
      __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1);
      __pyx_t_1 = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":565
 *         step_size = 4 if bigauss_fit else 3
 *         for index, value in enumerate(res.x[2::step_size]):
 *           if value < min_spacing:             # <<<<<<<<<<<<<<
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 565, __pyx_L1_error)
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 565, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":566
 *         for index, value in enumerate(res.x[2::step_size]):
 *           if value < min_spacing:
 *             res.x[2+index*step_size] = min_spacing             # <<<<<<<<<<<<<<
 *         if bigauss_fit:
 *           for index, value in enumerate(res.x[3::step_size]):
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 566, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_50 = PyNumber_Multiply(__pyx_v_index, __pyx_v_step_size); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 566, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __pyx_t_14 = __Pyx_PyInt_AddCObj(__pyx_int_2, __pyx_t_50, 2, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 566, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
        if (unlikely(PyObject_SetItem(__pyx_t_3, __pyx_t_14, __pyx_v_min_spacing) < 0)) __PYX_ERR(0, 566, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "pyquant/cpeaks.pyx":565
 *         step_size = 4 if bigauss_fit else 3
 *         for index, value in enumerate(res.x[2::step_size]):
 *           if value < min_spacing:             # <<<<<<<<<<<<<<
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:
 */
      }

      /* "pyquant/cpeaks.pyx":564
 *         res.bic = bic
 *         step_size = 4 if bigauss_fit else 3
 *         for index, value in enumerate(res.x[2::step_size]):             # <<<<<<<<<<<<<<
 *           if value < min_spacing:
 *             res.x[2+index*step_size] = min_spacing
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":567
 *           if value < min_spacing:
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:             # <<<<<<<<<<<<<<
 *           for index, value in enumerate(res.x[3::step_size]):
 *             if value < min_spacing:
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 567, __pyx_L1_error)
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":568
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:
 *           for index, value in enumerate(res.x[3::step_size]):             # <<<<<<<<<<<<<<
 *             if value < min_spacing:
 *               res.x[3+index*step_size] = min_spacing
 */
      __Pyx_INCREF(__pyx_int_0);
      __pyx_t_1 = __pyx_int_0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_14 = PySlice_New(__pyx_int_3, Py_None, __pyx_v_step_size); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 568, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_3 = PyObject_GetItem(__pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_14 = __pyx_t_3; __Pyx_INCREF(__pyx_t_14); __pyx_t_30 = 0;
        __pyx_t_31 = NULL;
      } else {
        __pyx_t_30 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 568, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_31 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 568, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_31)) {
          if (likely(PyList_CheckExact(__pyx_t_14))) {
            if (__pyx_t_30 >= PyList_GET_SIZE(__pyx_t_14)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_30); __Pyx_INCREF(__pyx_t_3); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 568, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_30 >= PyTuple_GET_SIZE(__pyx_t_14)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_30); __Pyx_INCREF(__pyx_t_3); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 568, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_14, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_31(__pyx_t_14);
          if (unlikely(!__pyx_t_3)) {
            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, 568, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
        __pyx_t_3 = 0;
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_1);
        __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1);
        __pyx_t_1 = __pyx_t_3;
        __pyx_t_3 = 0;

        /* "pyquant/cpeaks.pyx":569
 *         if bigauss_fit:
 *           for index, value in enumerate(res.x[3::step_size]):
 *             if value < min_spacing:             # <<<<<<<<<<<<<<
 *               res.x[3+index*step_size] = min_spacing
 *         # does this data contain our rt peak?
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_v_min_spacing, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error)
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 569, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":570
 *           for index, value in enumerate(res.x[3::step_size]):
 *             if value < min_spacing:
 *               res.x[3+index*step_size] = min_spacing             # <<<<<<<<<<<<<<
 *         # does this data contain our rt peak?
 *         res._contains_rt = False
 */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = PyNumber_Multiply(__pyx_v_index, __pyx_v_step_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 570, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_50 = __Pyx_PyInt_AddCObj(__pyx_int_3, __pyx_t_2, 3, 0); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 570, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_50);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(PyObject_SetItem(__pyx_t_3, __pyx_t_50, __pyx_v_min_spacing) < 0)) __PYX_ERR(0, 570, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;

          /* "pyquant/cpeaks.pyx":569
 *         if bigauss_fit:
 *           for index, value in enumerate(res.x[3::step_size]):
 *             if value < min_spacing:             # <<<<<<<<<<<<<<
 *               res.x[3+index*step_size] = min_spacing
 *         # does this data contain our rt peak?
 */
        }

        /* "pyquant/cpeaks.pyx":568
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:
 *           for index, value in enumerate(res.x[3::step_size]):             # <<<<<<<<<<<<<<
 *             if value < min_spacing:
 *               res.x[3+index*step_size] = min_spacing
 */
      }
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":567
 *           if value < min_spacing:
 *             res.x[2+index*step_size] = min_spacing
 *         if bigauss_fit:             # <<<<<<<<<<<<<<
 *           for index, value in enumerate(res.x[3::step_size]):
 *             if value < min_spacing:
 */
    }

    /* "pyquant/cpeaks.pyx":572
 *               res.x[3+index*step_size] = min_spacing
 *         # does this data contain our rt peak?
 *         res._contains_rt = False             # <<<<<<<<<<<<<<
 *         if rt_peak != 0:
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_res, __pyx_n_s_contains_rt, Py_False) < 0) __PYX_ERR(0, 572, __pyx_L1_error)

    /* "pyquant/cpeaks.pyx":573
 *         # does this data contain our rt peak?
 *         res._contains_rt = False
 *         if rt_peak != 0:             # <<<<<<<<<<<<<<
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):
 *                 mean = res.x[i]
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_rt_peak, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":574
 *         res._contains_rt = False
 *         if rt_peak != 0:
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):             # <<<<<<<<<<<<<<
 *                 mean = res.x[i]
 *                 lstd = res.x[i+1]
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 574, __pyx_L1_error)
      if (__pyx_t_10) {
        __Pyx_INCREF(__pyx_int_4);
        __pyx_t_1 = __pyx_int_4;
      } else {
        __Pyx_INCREF(__pyx_int_3);
        __pyx_t_1 = __pyx_int_3;
      }
      __pyx_t_50 = PyTuple_New(3); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_GIVEREF(__pyx_int_1);
      PyTuple_SET_ITEM(__pyx_t_50, 0, __pyx_int_1);
      __Pyx_GIVEREF(__pyx_t_14);
      PyTuple_SET_ITEM(__pyx_t_50, 1, __pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_50, 2, __pyx_t_1);
      __pyx_t_14 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_t_50, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
        __pyx_t_50 = __pyx_t_1; __Pyx_INCREF(__pyx_t_50); __pyx_t_30 = 0;
        __pyx_t_31 = NULL;
      } else {
        __pyx_t_30 = -1; __pyx_t_50 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 574, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __pyx_t_31 = Py_TYPE(__pyx_t_50)->tp_iternext; if (unlikely(!__pyx_t_31)) __PYX_ERR(0, 574, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      for (;;) {
        if (likely(!__pyx_t_31)) {
          if (likely(PyList_CheckExact(__pyx_t_50))) {
            if (__pyx_t_30 >= PyList_GET_SIZE(__pyx_t_50)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_1 = PyList_GET_ITEM(__pyx_t_50, __pyx_t_30); __Pyx_INCREF(__pyx_t_1); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 574, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_50, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          } else {
            if (__pyx_t_30 >= PyTuple_GET_SIZE(__pyx_t_50)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_50, __pyx_t_30); __Pyx_INCREF(__pyx_t_1); __pyx_t_30++; if (unlikely(0 < 0)) __PYX_ERR(0, 574, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_50, __pyx_t_30); __pyx_t_30++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          }
        } else {
          __pyx_t_1 = __pyx_t_31(__pyx_t_50);
          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, 574, __pyx_L1_error)
            }
            break;
          }
          __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, 574, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_v_i = __pyx_t_5;

        /* "pyquant/cpeaks.pyx":575
 *         if rt_peak != 0:
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):
 *                 mean = res.x[i]             # <<<<<<<<<<<<<<
 *                 lstd = res.x[i+1]
 *                 if bigauss_fit:
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_14 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 575, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF_SET(__pyx_v_mean, __pyx_t_14);
        __pyx_t_14 = 0;

        /* "pyquant/cpeaks.pyx":576
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):
 *                 mean = res.x[i]
 *                 lstd = res.x[i+1]             # <<<<<<<<<<<<<<
 *                 if bigauss_fit:
 *                     rstd = res.x[i+2]
 */
        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 576, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_21 = (__pyx_v_i + 1);
        __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_14, __pyx_t_21, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_XDECREF_SET(__pyx_v_lstd, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "pyquant/cpeaks.pyx":577
 *                 mean = res.x[i]
 *                 lstd = res.x[i+1]
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     rstd = res.x[i+2]
 *                 else:
 */
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_bigauss_fit); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 577, __pyx_L1_error)
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":578
 *                 lstd = res.x[i+1]
 *                 if bigauss_fit:
 *                     rstd = res.x[i+2]             # <<<<<<<<<<<<<<
 *                 else:
 *                     rstd = lstd
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 578, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_21 = (__pyx_v_i + 2);
          __pyx_t_14 = __Pyx_GetItemInt(__pyx_t_1, __pyx_t_21, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 578, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_rstd, __pyx_t_14);
          __pyx_t_14 = 0;

          /* "pyquant/cpeaks.pyx":577
 *                 mean = res.x[i]
 *                 lstd = res.x[i+1]
 *                 if bigauss_fit:             # <<<<<<<<<<<<<<
 *                     rstd = res.x[i+2]
 *                 else:
 */
          goto __pyx_L108;
        }

        /* "pyquant/cpeaks.pyx":580
 *                     rstd = res.x[i+2]
 *                 else:
 *                     rstd = lstd             # <<<<<<<<<<<<<<
 *                 if mean-lstd*2 < rt_peak < mean+rstd*2:
 *                     res._contains_rt = True
 */
        /*else*/ {
          __Pyx_INCREF(__pyx_v_lstd);
          __Pyx_XDECREF_SET(__pyx_v_rstd, __pyx_v_lstd);
        }
        __pyx_L108:;

        /* "pyquant/cpeaks.pyx":581
 *                 else:
 *                     rstd = lstd
 *                 if mean-lstd*2 < rt_peak < mean+rstd*2:             # <<<<<<<<<<<<<<
 *                     res._contains_rt = True
 * 
 */
        __pyx_t_14 = PyNumber_Multiply(__pyx_v_lstd, __pyx_int_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 581, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_1 = PyNumber_Subtract(__pyx_v_mean, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = PyObject_RichCompare(__pyx_t_1, __pyx_v_rt_peak, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 581, __pyx_L1_error)
        if (__Pyx_PyObject_IsTrue(__pyx_t_14)) {
          __Pyx_DECREF(__pyx_t_14);
          __pyx_t_3 = PyNumber_Multiply(__pyx_v_rstd, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 581, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = PyNumber_Add(__pyx_v_mean, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_14 = PyObject_RichCompare(__pyx_v_rt_peak, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 581, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 581, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        if (__pyx_t_10) {

          /* "pyquant/cpeaks.pyx":582
 *                     rstd = lstd
 *                 if mean-lstd*2 < rt_peak < mean+rstd*2:
 *                     res._contains_rt = True             # <<<<<<<<<<<<<<
 * 
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):
 */
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_res, __pyx_n_s_contains_rt, Py_True) < 0) __PYX_ERR(0, 582, __pyx_L1_error)

          /* "pyquant/cpeaks.pyx":581
 *                 else:
 *                     rstd = lstd
 *                 if mean-lstd*2 < rt_peak < mean+rstd*2:             # <<<<<<<<<<<<<<
 *                     res._contains_rt = True
 * 
 */
        }

        /* "pyquant/cpeaks.pyx":574
 *         res._contains_rt = False
 *         if rt_peak != 0:
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):             # <<<<<<<<<<<<<<
 *                 mean = res.x[i]
 *                 lstd = res.x[i+1]
 */
      }
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;

      /* "pyquant/cpeaks.pyx":573
 *         # does this data contain our rt peak?
 *         res._contains_rt = False
 *         if rt_peak != 0:             # <<<<<<<<<<<<<<
 *             for i in xrange(1, res.x.size, 4 if bigauss_fit else 3):
 *                 mean = res.x[i]
 */
    }

    /* "pyquant/cpeaks.pyx":584
 *                     res._contains_rt = True
 * 
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):             # <<<<<<<<<<<<<<
 *             if debug:
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 */
    __pyx_t_17 = ((__pyx_v_bic < __pyx_v_lowest_bic) != 0);
    if (!__pyx_t_17) {
    } else {
      __pyx_t_10 = __pyx_t_17;
      goto __pyx_L111_bool_binop_done;
    }
    __pyx_t_50 = __Pyx_GetAttr3(__pyx_v_best_res, __pyx_n_s_contains_rt, Py_False); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_50);
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_50); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
    if (__pyx_t_17) {
    } else {
      __pyx_t_10 = __pyx_t_17;
      goto __pyx_L111_bool_binop_done;
    }
    __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_contains_rt); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_50);
    __pyx_t_14 = PyObject_RichCompare(__pyx_t_50, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 584, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_10 = __pyx_t_17;
    __pyx_L111_bool_binop_done:;
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":585
 * 
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:
 */
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 585, __pyx_L1_error)
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":586
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):
 *             if debug:
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))             # <<<<<<<<<<<<<<
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:
 *                 continue
 */
        __pyx_t_50 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_50, __pyx_n_s_stderr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
        __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_write); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_50);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__23, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyFloat_FromDouble(__pyx_v_bic); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_13 = PyFloat_FromDouble(__pyx_v_lowest_bic); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_9 = NULL;
        __pyx_t_30 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(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);
            __pyx_t_30 = 1;
          }
        }
        __pyx_t_34 = PyTuple_New(2+__pyx_t_30); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_34);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_34, 0+__pyx_t_30, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_34, 1+__pyx_t_30, __pyx_t_13);
        __pyx_t_3 = 0;
        __pyx_t_13 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_34, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 586, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_50))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_50);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_50);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_50, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_50, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 586, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_14);
        } else {
          __pyx_t_34 = PyTuple_New(1+1); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 586, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_34);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_34, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_34, 0+1, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_50, __pyx_t_34, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 586, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
        }
        __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "pyquant/cpeaks.pyx":585
 * 
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):
 *             if debug:             # <<<<<<<<<<<<<<
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:
 */
      }

      /* "pyquant/cpeaks.pyx":587
 *             if debug:
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:             # <<<<<<<<<<<<<<
 *                 continue
 *             best_fit = np.copy(res.x)
 */
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_contains_rt); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_50 = PyObject_RichCompare(__pyx_t_14, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_50); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_50); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L116_bool_binop_done;
      }
      __pyx_t_50 = PyObject_RichCompare(__pyx_v_best_res, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_50); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 587, __pyx_L1_error)
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_50); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L116_bool_binop_done;
      }
      __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_v_best_res, __pyx_n_s_contains_rt); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_14 = PyObject_RichCompare(__pyx_t_50, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 587, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_10 = __pyx_t_17;
      __pyx_L116_bool_binop_done:;
      if (__pyx_t_10) {

        /* "pyquant/cpeaks.pyx":588
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:
 *                 continue             # <<<<<<<<<<<<<<
 *             best_fit = np.copy(res.x)
 *             best_res = res
 */
        goto __pyx_L46_continue;

        /* "pyquant/cpeaks.pyx":587
 *             if debug:
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:             # <<<<<<<<<<<<<<
 *                 continue
 *             best_fit = np.copy(res.x)
 */
      }

      /* "pyquant/cpeaks.pyx":589
 *             if res._contains_rt == False and best_res != 0 and best_res._contains_rt == True:
 *                 continue
 *             best_fit = np.copy(res.x)             # <<<<<<<<<<<<<<
 *             best_res = res
 *             best_rss = res.fun
 */
      __pyx_t_50 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 589, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_50, __pyx_n_s_copy); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 589, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_34);
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_x); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 589, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_34))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_34);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_34);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_34, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_34, __pyx_t_50); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 589, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
        __Pyx_GOTREF(__pyx_t_14);
      } else {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 589, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_GIVEREF(__pyx_t_50);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_50);
        __pyx_t_50 = 0;
        __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_34, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 589, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
      if (!(likely(((__pyx_t_14) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_14, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 589, __pyx_L1_error)
      __pyx_t_4 = ((PyArrayObject *)__pyx_t_14);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_best_fit.rcbuffer->pybuffer);
        __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best_fit.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_5 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_best_fit.rcbuffer->pybuffer, (PyObject*)__pyx_v_best_fit, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
          }
        }
        __pyx_pybuffernd_best_fit.diminfo[0].strides = __pyx_pybuffernd_best_fit.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_best_fit.diminfo[0].shape = __pyx_pybuffernd_best_fit.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 589, __pyx_L1_error)
      }
      __pyx_t_4 = 0;
      __Pyx_XDECREF_SET(__pyx_v_best_fit, ((PyArrayObject *)__pyx_t_14));
      __pyx_t_14 = 0;

      /* "pyquant/cpeaks.pyx":590
 *                 continue
 *             best_fit = np.copy(res.x)
 *             best_res = res             # <<<<<<<<<<<<<<
 *             best_rss = res.fun
 *             lowest_bic = bic
 */
      __Pyx_INCREF(__pyx_v_res);
      __Pyx_DECREF_SET(__pyx_v_best_res, __pyx_v_res);

      /* "pyquant/cpeaks.pyx":591
 *             best_fit = np.copy(res.x)
 *             best_res = res
 *             best_rss = res.fun             # <<<<<<<<<<<<<<
 *             lowest_bic = bic
 *         if debug:
 */
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_res, __pyx_n_s_fun); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 591, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_t_14); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 591, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_v_best_rss = __pyx_t_12;

      /* "pyquant/cpeaks.pyx":592
 *             best_res = res
 *             best_rss = res.fun
 *             lowest_bic = bic             # <<<<<<<<<<<<<<
 *         if debug:
 *             sys.stderr.write('{} - best: {}'.format(res, best_fit))
 */
      __pyx_v_lowest_bic = __pyx_v_bic;

      /* "pyquant/cpeaks.pyx":584
 *                     res._contains_rt = True
 * 
 *         if bic < lowest_bic or (getattr(best_res, '_contains_rt', False) and res._contains_rt == True):             # <<<<<<<<<<<<<<
 *             if debug:
 *                 sys.stderr.write('{} < {}'.format(bic, lowest_bic))
 */
    }

    /* "pyquant/cpeaks.pyx":593
 *             best_rss = res.fun
 *             lowest_bic = bic
 *         if debug:             # <<<<<<<<<<<<<<
 *             sys.stderr.write('{} - best: {}'.format(res, best_fit))
 * 
 */
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 593, __pyx_L1_error)
    if (__pyx_t_10) {

      /* "pyquant/cpeaks.pyx":594
 *             lowest_bic = bic
 *         if debug:
 *             sys.stderr.write('{} - best: {}'.format(res, best_fit))             # <<<<<<<<<<<<<<
 * 
 *     return best_fit, best_rss
 */
      __pyx_t_34 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_34);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_34, __pyx_n_s_stderr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
      __pyx_t_34 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_write); if (unlikely(!__pyx_t_34)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_34);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_50 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_best, __pyx_n_s_format); if (unlikely(!__pyx_t_50)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_50);
      __pyx_t_1 = NULL;
      __pyx_t_30 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_50))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_50);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_50);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_50, function);
          __pyx_t_30 = 1;
        }
      }
      __pyx_t_13 = PyTuple_New(2+__pyx_t_30); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_res);
      __Pyx_GIVEREF(__pyx_v_res);
      PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_30, __pyx_v_res);
      __Pyx_INCREF(((PyObject *)__pyx_v_best_fit));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_best_fit));
      PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_30, ((PyObject *)__pyx_v_best_fit));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_50, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0;
      __pyx_t_50 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_34))) {
        __pyx_t_50 = PyMethod_GET_SELF(__pyx_t_34);
        if (likely(__pyx_t_50)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_34);
          __Pyx_INCREF(__pyx_t_50);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_34, function);
        }
      }
      if (!__pyx_t_50) {
        __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_34, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_14);
      } else {
        __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_50); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_50); __pyx_t_50 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_34, __pyx_t_13, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_34); __pyx_t_34 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

      /* "pyquant/cpeaks.pyx":593
 *             best_rss = res.fun
 *             lowest_bic = bic
 *         if debug:             # <<<<<<<<<<<<<<
 *             sys.stderr.write('{} - best: {}'.format(res, best_fit))
 * 
 */
    }

    /* "pyquant/cpeaks.pyx":426
 *     if debug:
 *         sys.stderr.write('final peaks: {}\n'.format(final_peaks))
 *     for peak_width, peak_info in final_peaks.items():             # <<<<<<<<<<<<<<
 *         row_peaks = peak_info['peaks']
 *         if debug:
 */
    __pyx_L46_continue:;
  }
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":596
 *             sys.stderr.write('{} - best: {}'.format(res, best_fit))
 * 
 *     return best_fit, best_rss             # <<<<<<<<<<<<<<
 * 
 * cdef tuple findPeak(np.ndarray[FLOAT_t, ndim=1] y, int srt):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_15 = PyFloat_FromDouble(__pyx_v_best_rss); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 596, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 596, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_INCREF(((PyObject *)__pyx_v_best_fit));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_best_fit));
  PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_best_fit));
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_15);
  __pyx_t_15 = 0;
  __pyx_r = ((PyObject*)__pyx_t_14);
  __pyx_t_14 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":315
 * 
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,             # <<<<<<<<<<<<<<
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 */

  /* 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_9);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_34);
  __Pyx_XDECREF(__pyx_t_50);
  { 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_best_fit.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minima_array.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findAllPeaks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_best_fit.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_larger_peaks.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minima_array.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_indices.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peak_values.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_peaks.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_smaller_peaks.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_peaks.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_fit_func);
  __Pyx_XDECREF(__pyx_v_jacobian);
  __Pyx_XDECREF((PyObject *)__pyx_v_row_peaks);
  __Pyx_XDECREF((PyObject *)__pyx_v_smaller_peaks);
  __Pyx_XDECREF((PyObject *)__pyx_v_larger_peaks);
  __Pyx_XDECREF((PyObject *)__pyx_v_minima_array);
  __Pyx_XDECREF(__pyx_v_minima);
  __Pyx_XDECREF(__pyx_v_fit_accuracy);
  __Pyx_XDECREF(__pyx_v_smaller_minima);
  __Pyx_XDECREF(__pyx_v_larger_minima);
  __Pyx_XDECREF(__pyx_v_guess);
  __Pyx_XDECREF(__pyx_v_bnds);
  __Pyx_XDECREF(__pyx_v_peaks_found);
  __Pyx_XDECREF(__pyx_v_final_peaks);
  __Pyx_XDECREF(__pyx_v_peak_info);
  __Pyx_XDECREF((PyObject *)__pyx_v_peak_values);
  __Pyx_XDECREF((PyObject *)__pyx_v_peak_indices);
  __Pyx_XDECREF((PyObject *)__pyx_v_ydata);
  __Pyx_XDECREF((PyObject *)__pyx_v_ydata_peaks);
  __Pyx_XDECREF((PyObject *)__pyx_v_best_fit);
  __Pyx_XDECREF(__pyx_v_mapper);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_opts);
  __Pyx_XDECREF(__pyx_v_routines);
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XDECREF(__pyx_v_routine);
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_best_res);
  __Pyx_XDECREF(__pyx_v_min_spacing);
  __Pyx_XDECREF(__pyx_v_peak_range);
  __Pyx_XDECREF(__pyx_v_initial_bounds);
  __Pyx_XDECREF(__pyx_v_skip_peaks);
  __Pyx_XDECREF(__pyx_v_fitted_peaks);
  __Pyx_XDECREF(__pyx_v_peak_num);
  __Pyx_XDECREF(__pyx_v_peak_index);
  __Pyx_XDECREF(__pyx_v_step_size);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_mean);
  __Pyx_XDECREF(__pyx_v_lstd);
  __Pyx_XDECREF(__pyx_v_rstd);
  __Pyx_XDECREF(__pyx_v_peak_width_start);
  __Pyx_XDECREF(__pyx_v_amplitude_filter);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_19findAllPeaks(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_19findAllPeaks(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata_original = 0;
  float __pyx_v_min_dist;
  PyObject *__pyx_v_filter = 0;
  PyObject *__pyx_v_bigauss_fit = 0;
  PyObject *__pyx_v_rt_peak = 0;
  PyObject *__pyx_v_mrm = 0;
  int __pyx_v_max_peaks;
  PyObject *__pyx_v_debug = 0;
  PyObject *__pyx_v_peak_width_start = 0;
  PyObject *__pyx_v_snr = 0;
  PyObject *__pyx_v_amplitude_filter = 0;
  PyObject *__pyx_v_peak_width_end = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("findAllPeaks (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_ydata_original,&__pyx_n_s_min_dist,&__pyx_n_s_filter,&__pyx_n_s_bigauss_fit,&__pyx_n_s_rt_peak,&__pyx_n_s_mrm,&__pyx_n_s_max_peaks,&__pyx_n_s_debug,&__pyx_n_s_peak_width_start,&__pyx_n_s_snr,&__pyx_n_s_amplitude_filter,&__pyx_n_s_peak_width_end,0};
    PyObject* values[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};

    /* "pyquant/cpeaks.pyx":316
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,             # <<<<<<<<<<<<<<
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 *                          peak_width_end=4):
 */
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_False);
    values[5] = ((PyObject *)__pyx_float_0_0);
    values[6] = ((PyObject *)Py_False);

    /* "pyquant/cpeaks.pyx":317
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,             # <<<<<<<<<<<<<<
 *                          peak_width_end=4):
 *     cdef object fit_func, jacobian
 */
    values[8] = ((PyObject *)Py_False);
    values[9] = ((PyObject *)__pyx_int_2);
    values[10] = ((PyObject *)__pyx_int_0);
    values[11] = ((PyObject *)__pyx_int_0);
    values[12] = ((PyObject *)__pyx_int_4);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        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_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata_original)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("findAllPeaks", 0, 2, 13, 1); __PYX_ERR(0, 315, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_min_dist);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_filter);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_bigauss_fit);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rt_peak);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mrm);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_peaks);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_debug);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_peak_width_start);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_snr);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_amplitude_filter);
          if (value) { values[11] = value; kw_args--; }
        }
        case 12:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_peak_width_end);
          if (value) { values[12] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "findAllPeaks") < 0)) __PYX_ERR(0, 315, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_ydata_original = ((PyArrayObject *)values[1]);
    if (values[2]) {
      __pyx_v_min_dist = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_min_dist == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 316, __pyx_L3_error)
    } else {
      __pyx_v_min_dist = ((float)0.0);
    }
    __pyx_v_filter = values[3];
    __pyx_v_bigauss_fit = values[4];
    __pyx_v_rt_peak = values[5];
    __pyx_v_mrm = values[6];
    if (values[7]) {
      __pyx_v_max_peaks = __Pyx_PyInt_As_int(values[7]); if (unlikely((__pyx_v_max_peaks == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 317, __pyx_L3_error)
    } else {
      __pyx_v_max_peaks = ((int)4);
    }
    __pyx_v_debug = values[8];
    __pyx_v_peak_width_start = values[9];
    __pyx_v_snr = values[10];
    __pyx_v_amplitude_filter = values[11];
    __pyx_v_peak_width_end = values[12];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("findAllPeaks", 0, 2, 13, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 315, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.findAllPeaks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 315, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata_original), __pyx_ptype_5numpy_ndarray, 1, "ydata_original", 0))) __PYX_ERR(0, 315, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_18findAllPeaks(__pyx_self, __pyx_v_xdata, __pyx_v_ydata_original, __pyx_v_min_dist, __pyx_v_filter, __pyx_v_bigauss_fit, __pyx_v_rt_peak, __pyx_v_mrm, __pyx_v_max_peaks, __pyx_v_debug, __pyx_v_peak_width_start, __pyx_v_snr, __pyx_v_amplitude_filter, __pyx_v_peak_width_end);

  /* "pyquant/cpeaks.pyx":315
 * 
 * @cython.boundscheck(False)
 * cpdef tuple findAllPeaks(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata_original,             # <<<<<<<<<<<<<<
 *                          float min_dist=0, filter=False, bigauss_fit=False, rt_peak=0.0, mrm=False,
 *                          int max_peaks=4, debug=False, peak_width_start=2, snr=0, amplitude_filter=0,
 */

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_18findAllPeaks(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata_original, float __pyx_v_min_dist, PyObject *__pyx_v_filter, PyObject *__pyx_v_bigauss_fit, PyObject *__pyx_v_rt_peak, PyObject *__pyx_v_mrm, int __pyx_v_max_peaks, PyObject *__pyx_v_debug, PyObject *__pyx_v_peak_width_start, PyObject *__pyx_v_snr, PyObject *__pyx_v_amplitude_filter, PyObject *__pyx_v_peak_width_end) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata_original;
  __Pyx_Buffer __pyx_pybuffer_ydata_original;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7pyquant_6cpeaks_findAllPeaks __pyx_t_2;
  __Pyx_RefNannySetupContext("findAllPeaks", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata_original.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata_original.refcount = 0;
  __pyx_pybuffernd_ydata_original.data = NULL;
  __pyx_pybuffernd_ydata_original.rcbuffer = &__pyx_pybuffer_ydata_original;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 315, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata_original, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 315, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata_original.diminfo[0].strides = __pyx_pybuffernd_ydata_original.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata_original.diminfo[0].shape = __pyx_pybuffernd_ydata_original.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 11;
  __pyx_t_2.min_dist = __pyx_v_min_dist;
  __pyx_t_2.filter = __pyx_v_filter;
  __pyx_t_2.bigauss_fit = __pyx_v_bigauss_fit;
  __pyx_t_2.rt_peak = __pyx_v_rt_peak;
  __pyx_t_2.mrm = __pyx_v_mrm;
  __pyx_t_2.max_peaks = __pyx_v_max_peaks;
  __pyx_t_2.debug = __pyx_v_debug;
  __pyx_t_2.peak_width_start = __pyx_v_peak_width_start;
  __pyx_t_2.snr = __pyx_v_snr;
  __pyx_t_2.amplitude_filter = __pyx_v_amplitude_filter;
  __pyx_t_2.peak_width_end = __pyx_v_peak_width_end;
  __pyx_t_1 = __pyx_f_7pyquant_6cpeaks_findAllPeaks(__pyx_v_xdata, __pyx_v_ydata_original, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findAllPeaks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata_original.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":598
 *     return best_fit, best_rss
 * 
 * cdef tuple findPeak(np.ndarray[FLOAT_t, ndim=1] y, int srt):             # <<<<<<<<<<<<<<
 *     # check our SNR, if it's low, lessen our window
 *     cdef int left_offset = 1
 */

static PyObject *__pyx_f_7pyquant_6cpeaks_findPeak(PyArrayObject *__pyx_v_y, int __pyx_v_srt) {
  int __pyx_v_left_offset;
  int __pyx_v_right_offset;
  int __pyx_v_lsrt;
  int __pyx_v_rsrt;
  float __pyx_v_peak;
  int __pyx_v_left;
  PyArrayObject *__pyx_v_grad = 0;
  int __pyx_v_slope_shifts;
  float __pyx_v_val;
  PyObject *__pyx_v_ishift = 0;
  PyObject *__pyx_v_shift = NULL;
  PyObject *__pyx_v_last_slope = NULL;
  PyObject *__pyx_v_slope = NULL;
  int __pyx_v_right;
  float __pyx_v_highest_val;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_grad;
  __Pyx_Buffer __pyx_pybuffer_grad;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_y;
  __Pyx_Buffer __pyx_pybuffer_y;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  __Pyx_RefNannySetupContext("findPeak", 0);
  __pyx_pybuffer_grad.pybuffer.buf = NULL;
  __pyx_pybuffer_grad.refcount = 0;
  __pyx_pybuffernd_grad.data = NULL;
  __pyx_pybuffernd_grad.rcbuffer = &__pyx_pybuffer_grad;
  __pyx_pybuffer_y.pybuffer.buf = NULL;
  __pyx_pybuffer_y.refcount = 0;
  __pyx_pybuffernd_y.data = NULL;
  __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 598, __pyx_L1_error)
  }
  __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":600
 * cdef tuple findPeak(np.ndarray[FLOAT_t, ndim=1] y, int srt):
 *     # check our SNR, if it's low, lessen our window
 *     cdef int left_offset = 1             # <<<<<<<<<<<<<<
 *     cdef int right_offset = 2
 *     cdef int lsrt = srt-left_offset if srt-left_offset > 0 else 0
 */
  __pyx_v_left_offset = 1;

  /* "pyquant/cpeaks.pyx":601
 *     # check our SNR, if it's low, lessen our window
 *     cdef int left_offset = 1
 *     cdef int right_offset = 2             # <<<<<<<<<<<<<<
 *     cdef int lsrt = srt-left_offset if srt-left_offset > 0 else 0
 *     cdef int rsrt = srt+right_offset if srt+right_offset < len(y) else len(y)
 */
  __pyx_v_right_offset = 2;

  /* "pyquant/cpeaks.pyx":602
 *     cdef int left_offset = 1
 *     cdef int right_offset = 2
 *     cdef int lsrt = srt-left_offset if srt-left_offset > 0 else 0             # <<<<<<<<<<<<<<
 *     cdef int rsrt = srt+right_offset if srt+right_offset < len(y) else len(y)
 *     cdef float peak = y[srt]
 */
  if ((((__pyx_v_srt - __pyx_v_left_offset) > 0) != 0)) {
    __pyx_t_1 = (__pyx_v_srt - __pyx_v_left_offset);
  } else {
    __pyx_t_1 = 0;
  }
  __pyx_v_lsrt = __pyx_t_1;

  /* "pyquant/cpeaks.pyx":603
 *     cdef int right_offset = 2
 *     cdef int lsrt = srt-left_offset if srt-left_offset > 0 else 0
 *     cdef int rsrt = srt+right_offset if srt+right_offset < len(y) else len(y)             # <<<<<<<<<<<<<<
 *     cdef float peak = y[srt]
 *     cdef int left = 0
 */
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_y)); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 603, __pyx_L1_error)
  if ((((__pyx_v_srt + __pyx_v_right_offset) < __pyx_t_3) != 0)) {
    __pyx_t_2 = (__pyx_v_srt + __pyx_v_right_offset);
  } else {
    __pyx_t_4 = PyObject_Length(((PyObject *)__pyx_v_y)); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 603, __pyx_L1_error)
    __pyx_t_2 = __pyx_t_4;
  }
  __pyx_v_rsrt = __pyx_t_2;

  /* "pyquant/cpeaks.pyx":604
 *     cdef int lsrt = srt-left_offset if srt-left_offset > 0 else 0
 *     cdef int rsrt = srt+right_offset if srt+right_offset < len(y) else len(y)
 *     cdef float peak = y[srt]             # <<<<<<<<<<<<<<
 *     cdef int left = 0
 *     cdef np.ndarray[FLOAT_t] grad
 */
  __pyx_t_5 = __pyx_v_srt;
  __pyx_t_1 = -1;
  if (__pyx_t_5 < 0) {
    __pyx_t_5 += __pyx_pybuffernd_y.diminfo[0].shape;
    if (unlikely(__pyx_t_5 < 0)) __pyx_t_1 = 0;
  } else if (unlikely(__pyx_t_5 >= __pyx_pybuffernd_y.diminfo[0].shape)) __pyx_t_1 = 0;
  if (unlikely(__pyx_t_1 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_1);
    __PYX_ERR(0, 604, __pyx_L1_error)
  }
  __pyx_v_peak = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_y.diminfo[0].strides));

  /* "pyquant/cpeaks.pyx":605
 *     cdef int rsrt = srt+right_offset if srt+right_offset < len(y) else len(y)
 *     cdef float peak = y[srt]
 *     cdef int left = 0             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t] grad
 *     cdef int slope_shifts
 */
  __pyx_v_left = 0;

  /* "pyquant/cpeaks.pyx":610
 *     cdef float val
 *     cdef str ishift
 *     grad = y[lsrt:rsrt]             # <<<<<<<<<<<<<<
 *     try:
 *         shift = sum(np.sign(np.gradient(grad)))
 */
  __pyx_t_6 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_y), __pyx_v_lsrt, __pyx_v_rsrt, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 610, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer);
    __pyx_t_1 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_1 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_v_grad, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_grad.diminfo[0].strides = __pyx_pybuffernd_grad.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_grad.diminfo[0].shape = __pyx_pybuffernd_grad.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 610, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_grad = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":611
 *     cdef str ishift
 *     grad = y[lsrt:rsrt]
 *     try:             # <<<<<<<<<<<<<<
 *         shift = sum(np.sign(np.gradient(grad)))
 *     except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
    __Pyx_XGOTREF(__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_8);
    /*try:*/ {

      /* "pyquant/cpeaks.pyx":612
 *     grad = y[lsrt:rsrt]
 *     try:
 *         shift = sum(np.sign(np.gradient(grad)))             # <<<<<<<<<<<<<<
 *     except ValueError:
 *         return 0, len(y)
 */
      __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_sign); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_gradient); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_14))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_14, function);
        }
      }
      if (!__pyx_t_13) {
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_14, ((PyObject *)__pyx_v_grad)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
      } else {
        __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_grad));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_grad));
        PyTuple_SET_ITEM(__pyx_t_15, 0+1, ((PyObject *)__pyx_v_grad));
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_15, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
        }
      }
      if (!__pyx_t_14) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL;
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_11);
        __pyx_t_11 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_15, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 612, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 612, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_v_shift = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pyquant/cpeaks.pyx":611
 *     cdef str ishift
 *     grad = y[lsrt:rsrt]
 *     try:             # <<<<<<<<<<<<<<
 *         shift = sum(np.sign(np.gradient(grad)))
 *     except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L10_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pyquant/cpeaks.pyx":613
 *     try:
 *         shift = sum(np.sign(np.gradient(grad)))
 *     except ValueError:             # <<<<<<<<<<<<<<
 *         return 0, len(y)
 *     shift = 'left' if shift < 0 else 'right'
 */
    __pyx_t_1 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_1) {
      __Pyx_AddTraceback("pyquant.cpeaks.findPeak", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_12, &__pyx_t_15) < 0) __PYX_ERR(0, 613, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GOTREF(__pyx_t_15);

      /* "pyquant/cpeaks.pyx":614
 *         shift = sum(np.sign(np.gradient(grad)))
 *     except ValueError:
 *         return 0, len(y)             # <<<<<<<<<<<<<<
 *     shift = 'left' if shift < 0 else 'right'
 *     ishift = shift
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_y)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 614, __pyx_L5_except_error)
      __pyx_t_11 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 614, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 614, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_r = ((PyObject*)__pyx_t_14);
      __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      goto __pyx_L6_except_return;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "pyquant/cpeaks.pyx":611
 *     cdef str ishift
 *     grad = y[lsrt:rsrt]
 *     try:             # <<<<<<<<<<<<<<
 *         shift = sum(np.sign(np.gradient(grad)))
 *     except ValueError:
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_9, __pyx_t_8);
    goto __pyx_L1_error;
    __pyx_L6_except_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_9, __pyx_t_8);
    goto __pyx_L0;
    __pyx_L10_try_end:;
  }

  /* "pyquant/cpeaks.pyx":615
 *     except ValueError:
 *         return 0, len(y)
 *     shift = 'left' if shift < 0 else 'right'             # <<<<<<<<<<<<<<
 *     ishift = shift
 *     slope_shifts = 0
 */
  __pyx_t_12 = PyObject_RichCompare(__pyx_v_shift, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 615, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 615, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  if (__pyx_t_16) {
    __Pyx_INCREF(__pyx_n_s_left);
    __pyx_t_15 = __pyx_n_s_left;
  } else {
    __Pyx_INCREF(__pyx_n_s_right);
    __pyx_t_15 = __pyx_n_s_right;
  }
  __Pyx_DECREF_SET(__pyx_v_shift, __pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":616
 *         return 0, len(y)
 *     shift = 'left' if shift < 0 else 'right'
 *     ishift = shift             # <<<<<<<<<<<<<<
 *     slope_shifts = 0
 *     last_slope = -1
 */
  if (!(likely(PyString_CheckExact(__pyx_v_shift))||((__pyx_v_shift) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_shift)->tp_name), 0))) __PYX_ERR(0, 616, __pyx_L1_error)
  __pyx_t_15 = __pyx_v_shift;
  __Pyx_INCREF(__pyx_t_15);
  __pyx_v_ishift = ((PyObject*)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pyquant/cpeaks.pyx":617
 *     shift = 'left' if shift < 0 else 'right'
 *     ishift = shift
 *     slope_shifts = 0             # <<<<<<<<<<<<<<
 *     last_slope = -1
 *     for left in xrange(srt-1, -1, -1):
 */
  __pyx_v_slope_shifts = 0;

  /* "pyquant/cpeaks.pyx":618
 *     ishift = shift
 *     slope_shifts = 0
 *     last_slope = -1             # <<<<<<<<<<<<<<
 *     for left in xrange(srt-1, -1, -1):
 *         val = y[left]
 */
  __Pyx_INCREF(__pyx_int_neg_1);
  __pyx_v_last_slope = __pyx_int_neg_1;

  /* "pyquant/cpeaks.pyx":619
 *     slope_shifts = 0
 *     last_slope = -1
 *     for left in xrange(srt-1, -1, -1):             # <<<<<<<<<<<<<<
 *         val = y[left]
 *         grad = y[left-2:left+1]
 */
  for (__pyx_t_1 = (__pyx_v_srt - 1); __pyx_t_1 > -1L; __pyx_t_1-=1) {
    __pyx_v_left = __pyx_t_1;

    /* "pyquant/cpeaks.pyx":620
 *     last_slope = -1
 *     for left in xrange(srt-1, -1, -1):
 *         val = y[left]             # <<<<<<<<<<<<<<
 *         grad = y[left-2:left+1]
 *         slope = None
 */
    __pyx_t_17 = __pyx_v_left;
    __pyx_t_18 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_pybuffernd_y.diminfo[0].shape;
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_y.diminfo[0].shape)) __pyx_t_18 = 0;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 620, __pyx_L1_error)
    }
    __pyx_v_val = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_y.diminfo[0].strides));

    /* "pyquant/cpeaks.pyx":621
 *     for left in xrange(srt-1, -1, -1):
 *         val = y[left]
 *         grad = y[left-2:left+1]             # <<<<<<<<<<<<<<
 *         slope = None
 *         if len(grad) >= 2:
 */
    __pyx_t_15 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_y), (__pyx_v_left - 2), (__pyx_v_left + 1), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 621, __pyx_L1_error)
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_15);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer);
      __pyx_t_18 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_18 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_v_grad, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
      }
      __pyx_pybuffernd_grad.diminfo[0].strides = __pyx_pybuffernd_grad.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_grad.diminfo[0].shape = __pyx_pybuffernd_grad.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 621, __pyx_L1_error)
    }
    __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_grad, ((PyArrayObject *)__pyx_t_15));
    __pyx_t_15 = 0;

    /* "pyquant/cpeaks.pyx":622
 *         val = y[left]
 *         grad = y[left-2:left+1]
 *         slope = None             # <<<<<<<<<<<<<<
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 */
    __Pyx_INCREF(Py_None);
    __Pyx_XDECREF_SET(__pyx_v_slope, Py_None);

    /* "pyquant/cpeaks.pyx":623
 *         grad = y[left-2:left+1]
 *         slope = None
 *         if len(grad) >= 2:             # <<<<<<<<<<<<<<
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 */
    __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_grad)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 623, __pyx_L1_error)
    __pyx_t_16 = ((__pyx_t_2 >= 2) != 0);
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":624
 *         slope = None
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))             # <<<<<<<<<<<<<<
 *             if slope < 0:
 *                 slope = 'right'
 */
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_sign); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_gradient); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      if (!__pyx_t_14) {
        __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_11, ((PyObject *)__pyx_v_grad)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
      } else {
        __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14); __pyx_t_14 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_grad));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_grad));
        PyTuple_SET_ITEM(__pyx_t_13, 0+1, ((PyObject *)__pyx_v_grad));
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_15);
      } else {
        __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL;
        __Pyx_GIVEREF(__pyx_t_12);
        PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_12);
        __pyx_t_12 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 624, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_15);
      __pyx_t_15 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_6, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 624, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF_SET(__pyx_v_slope, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":625
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:             # <<<<<<<<<<<<<<
 *                 slope = 'right'
 *             elif slope > 0:
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 625, __pyx_L1_error)
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 625, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":626
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 *                 slope = 'right'             # <<<<<<<<<<<<<<
 *             elif slope > 0:
 *                 slope = 'left'
 */
        __Pyx_INCREF(__pyx_n_s_right);
        __Pyx_DECREF_SET(__pyx_v_slope, __pyx_n_s_right);

        /* "pyquant/cpeaks.pyx":625
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:             # <<<<<<<<<<<<<<
 *                 slope = 'right'
 *             elif slope > 0:
 */
        goto __pyx_L16;
      }

      /* "pyquant/cpeaks.pyx":627
 *             if slope < 0:
 *                 slope = 'right'
 *             elif slope > 0:             # <<<<<<<<<<<<<<
 *                 slope = 'left'
 *         if last_slope != -1:
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 627, __pyx_L1_error)
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 627, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":628
 *                 slope = 'right'
 *             elif slope > 0:
 *                 slope = 'left'             # <<<<<<<<<<<<<<
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:
 */
        __Pyx_INCREF(__pyx_n_s_left);
        __Pyx_DECREF_SET(__pyx_v_slope, __pyx_n_s_left);

        /* "pyquant/cpeaks.pyx":627
 *             if slope < 0:
 *                 slope = 'right'
 *             elif slope > 0:             # <<<<<<<<<<<<<<
 *                 slope = 'left'
 *         if last_slope != -1:
 */
      }
      __pyx_L16:;

      /* "pyquant/cpeaks.pyx":623
 *         grad = y[left-2:left+1]
 *         slope = None
 *         if len(grad) >= 2:             # <<<<<<<<<<<<<<
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 */
    }

    /* "pyquant/cpeaks.pyx":629
 *             elif slope > 0:
 *                 slope = 'left'
 *         if last_slope != -1:             # <<<<<<<<<<<<<<
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 */
    __pyx_t_15 = PyObject_RichCompare(__pyx_v_last_slope, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 629, __pyx_L1_error)
    __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":630
 *                 slope = 'left'
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:             # <<<<<<<<<<<<<<
 *                 slope_shifts += 1
 *         last_slope = slope
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_last_slope, __pyx_v_slope, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 630, __pyx_L1_error)
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 630, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_19) {
      } else {
        __pyx_t_16 = __pyx_t_19;
        goto __pyx_L19_bool_binop_done;
      }
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 630, __pyx_L1_error)
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 630, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_16 = __pyx_t_19;
      __pyx_L19_bool_binop_done:;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":631
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1             # <<<<<<<<<<<<<<
 *         last_slope = slope
 *         if ishift == 'right' and ishift == slope:
 */
        __pyx_v_slope_shifts = (__pyx_v_slope_shifts + 1);

        /* "pyquant/cpeaks.pyx":630
 *                 slope = 'left'
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:             # <<<<<<<<<<<<<<
 *                 slope_shifts += 1
 *         last_slope = slope
 */
      }

      /* "pyquant/cpeaks.pyx":629
 *             elif slope > 0:
 *                 slope = 'left'
 *         if last_slope != -1:             # <<<<<<<<<<<<<<
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 */
    }

    /* "pyquant/cpeaks.pyx":632
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 *         last_slope = slope             # <<<<<<<<<<<<<<
 *         if ishift == 'right' and ishift == slope:
 *             break
 */
    __Pyx_INCREF(__pyx_v_slope);
    __Pyx_DECREF_SET(__pyx_v_last_slope, __pyx_v_slope);

    /* "pyquant/cpeaks.pyx":633
 *                 slope_shifts += 1
 *         last_slope = slope
 *         if ishift == 'right' and ishift == slope:             # <<<<<<<<<<<<<<
 *             break
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 */
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_n_s_right, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 633, __pyx_L1_error)
    __pyx_t_20 = (__pyx_t_19 != 0);
    if (__pyx_t_20) {
    } else {
      __pyx_t_16 = __pyx_t_20;
      goto __pyx_L22_bool_binop_done;
    }
    __pyx_t_20 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_v_slope, Py_EQ)); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 633, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_20;
    __pyx_L22_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":634
 *         last_slope = slope
 *         if ishift == 'right' and ishift == slope:
 *             break             # <<<<<<<<<<<<<<
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 *             break
 */
      goto __pyx_L14_break;

      /* "pyquant/cpeaks.pyx":633
 *                 slope_shifts += 1
 *         last_slope = slope
 *         if ishift == 'right' and ishift == slope:             # <<<<<<<<<<<<<<
 *             break
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 */
    }

    /* "pyquant/cpeaks.pyx":635
 *         if ishift == 'right' and ishift == slope:
 *             break
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:             # <<<<<<<<<<<<<<
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):
 */
    __pyx_t_20 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_n_s_left, Py_EQ)); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 635, __pyx_L1_error)
    __pyx_t_19 = (__pyx_t_20 != 0);
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_right, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 635, __pyx_L1_error)
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_19 = ((__pyx_v_slope_shifts > 1) != 0);
    __pyx_t_16 = __pyx_t_19;
    __pyx_L25_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":636
 *             break
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 *             break             # <<<<<<<<<<<<<<
 *         if val == 0 or (val > peak and slope != 'right'):
 *             if val == 0 or shift != 'left':
 */
      goto __pyx_L14_break;

      /* "pyquant/cpeaks.pyx":635
 *         if ishift == 'right' and ishift == slope:
 *             break
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:             # <<<<<<<<<<<<<<
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):
 */
    }

    /* "pyquant/cpeaks.pyx":637
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):             # <<<<<<<<<<<<<<
 *             if val == 0 or shift != 'left':
 *                 break
 */
    __pyx_t_19 = ((__pyx_v_val == 0.0) != 0);
    if (!__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L29_bool_binop_done;
    }
    __pyx_t_19 = ((__pyx_v_val > __pyx_v_peak) != 0);
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L29_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_right, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 637, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_19;
    __pyx_L29_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":638
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):
 *             if val == 0 or shift != 'left':             # <<<<<<<<<<<<<<
 *                 break
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl
 */
      __pyx_t_19 = ((__pyx_v_val == 0.0) != 0);
      if (!__pyx_t_19) {
      } else {
        __pyx_t_16 = __pyx_t_19;
        goto __pyx_L33_bool_binop_done;
      }
      __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_shift, __pyx_n_s_left, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 638, __pyx_L1_error)
      __pyx_t_16 = __pyx_t_19;
      __pyx_L33_bool_binop_done:;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":639
 *         if val == 0 or (val > peak and slope != 'right'):
 *             if val == 0 or shift != 'left':
 *                 break             # <<<<<<<<<<<<<<
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl
 *             shift = None
 */
        goto __pyx_L14_break;

        /* "pyquant/cpeaks.pyx":638
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):
 *             if val == 0 or shift != 'left':             # <<<<<<<<<<<<<<
 *                 break
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl
 */
      }

      /* "pyquant/cpeaks.pyx":637
 *         if ishift == 'left' and slope == 'right' and slope_shifts > 1:
 *             break
 *         if val == 0 or (val > peak and slope != 'right'):             # <<<<<<<<<<<<<<
 *             if val == 0 or shift != 'left':
 *                 break
 */
      goto __pyx_L28;
    }

    /* "pyquant/cpeaks.pyx":640
 *             if val == 0 or shift != 'left':
 *                 break
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl             # <<<<<<<<<<<<<<
 *             shift = None
 * 
 */
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_shift, __pyx_n_s_left, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 640, __pyx_L1_error)
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L35_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_right, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 640, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_19;
    __pyx_L35_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":641
 *                 break
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl
 *             shift = None             # <<<<<<<<<<<<<<
 * 
 *     cdef int right
 */
      __Pyx_INCREF(Py_None);
      __Pyx_DECREF_SET(__pyx_v_shift, Py_None);

      /* "pyquant/cpeaks.pyx":640
 *             if val == 0 or shift != 'left':
 *                 break
 *         elif shift == 'left' and slope != 'right':# slope != right logic: newsl             # <<<<<<<<<<<<<<
 *             shift = None
 * 
 */
    }
    __pyx_L28:;
  }
  __pyx_L14_break:;

  /* "pyquant/cpeaks.pyx":646
 *     cdef float highest_val
 * 
 *     right = len(y)             # <<<<<<<<<<<<<<
 *     shift = ishift
 *     highest_val = peak
 */
  __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_y)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 646, __pyx_L1_error)
  __pyx_v_right = __pyx_t_2;

  /* "pyquant/cpeaks.pyx":647
 * 
 *     right = len(y)
 *     shift = ishift             # <<<<<<<<<<<<<<
 *     highest_val = peak
 *     slope_shifts = 0
 */
  __Pyx_INCREF(__pyx_v_ishift);
  __Pyx_DECREF_SET(__pyx_v_shift, __pyx_v_ishift);

  /* "pyquant/cpeaks.pyx":648
 *     right = len(y)
 *     shift = ishift
 *     highest_val = peak             # <<<<<<<<<<<<<<
 *     slope_shifts = 0
 *     last_slope = -1
 */
  __pyx_v_highest_val = __pyx_v_peak;

  /* "pyquant/cpeaks.pyx":649
 *     shift = ishift
 *     highest_val = peak
 *     slope_shifts = 0             # <<<<<<<<<<<<<<
 *     last_slope = -1
 *     for right in xrange(srt+1, len(y)):
 */
  __pyx_v_slope_shifts = 0;

  /* "pyquant/cpeaks.pyx":650
 *     highest_val = peak
 *     slope_shifts = 0
 *     last_slope = -1             # <<<<<<<<<<<<<<
 *     for right in xrange(srt+1, len(y)):
 *         val = y[right]
 */
  __Pyx_INCREF(__pyx_int_neg_1);
  __Pyx_DECREF_SET(__pyx_v_last_slope, __pyx_int_neg_1);

  /* "pyquant/cpeaks.pyx":651
 *     slope_shifts = 0
 *     last_slope = -1
 *     for right in xrange(srt+1, len(y)):             # <<<<<<<<<<<<<<
 *         val = y[right]
 *         grad = y[right:right+3]
 */
  __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_y)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 651, __pyx_L1_error)
  for (__pyx_t_1 = (__pyx_v_srt + 1); __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) {
    __pyx_v_right = __pyx_t_1;

    /* "pyquant/cpeaks.pyx":652
 *     last_slope = -1
 *     for right in xrange(srt+1, len(y)):
 *         val = y[right]             # <<<<<<<<<<<<<<
 *         grad = y[right:right+3]
 *         slope = None
 */
    __pyx_t_21 = __pyx_v_right;
    __pyx_t_18 = -1;
    if (__pyx_t_21 < 0) {
      __pyx_t_21 += __pyx_pybuffernd_y.diminfo[0].shape;
      if (unlikely(__pyx_t_21 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_21 >= __pyx_pybuffernd_y.diminfo[0].shape)) __pyx_t_18 = 0;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 652, __pyx_L1_error)
    }
    __pyx_v_val = (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides));

    /* "pyquant/cpeaks.pyx":653
 *     for right in xrange(srt+1, len(y)):
 *         val = y[right]
 *         grad = y[right:right+3]             # <<<<<<<<<<<<<<
 *         slope = None
 *         if len(grad) >= 2:
 */
    __pyx_t_15 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_y), __pyx_v_right, (__pyx_v_right + 3), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 653, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 653, __pyx_L1_error)
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_15);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer);
      __pyx_t_18 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_18 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_grad.rcbuffer->pybuffer, (PyObject*)__pyx_v_grad, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
      }
      __pyx_pybuffernd_grad.diminfo[0].strides = __pyx_pybuffernd_grad.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_grad.diminfo[0].shape = __pyx_pybuffernd_grad.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 653, __pyx_L1_error)
    }
    __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_grad, ((PyArrayObject *)__pyx_t_15));
    __pyx_t_15 = 0;

    /* "pyquant/cpeaks.pyx":654
 *         val = y[right]
 *         grad = y[right:right+3]
 *         slope = None             # <<<<<<<<<<<<<<
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 */
    __Pyx_INCREF(Py_None);
    __Pyx_XDECREF_SET(__pyx_v_slope, Py_None);

    /* "pyquant/cpeaks.pyx":655
 *         grad = y[right:right+3]
 *         slope = None
 *         if len(grad) >= 2:             # <<<<<<<<<<<<<<
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 */
    __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_grad)); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 655, __pyx_L1_error)
    __pyx_t_16 = ((__pyx_t_3 >= 2) != 0);
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":656
 *         slope = None
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))             # <<<<<<<<<<<<<<
 *             if slope < 0:
 *                 slope = 'right'
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sign); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_gradient); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      if (!__pyx_t_12) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_11, ((PyObject *)__pyx_v_grad)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12); __pyx_t_12 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_grad));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_grad));
        PyTuple_SET_ITEM(__pyx_t_14, 0+1, ((PyObject *)__pyx_v_grad));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_6); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_15);
      } else {
        __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_11); __pyx_t_11 = NULL;
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_14, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_15);
      __pyx_t_15 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_13, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF_SET(__pyx_v_slope, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "pyquant/cpeaks.pyx":657
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:             # <<<<<<<<<<<<<<
 *                 slope = 'right'
 *             elif slope > 0:
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 657, __pyx_L1_error)
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 657, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":658
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 *                 slope = 'right'             # <<<<<<<<<<<<<<
 *             elif slope > 0:
 *                 slope = 'left'
 */
        __Pyx_INCREF(__pyx_n_s_right);
        __Pyx_DECREF_SET(__pyx_v_slope, __pyx_n_s_right);

        /* "pyquant/cpeaks.pyx":657
 *         if len(grad) >= 2:
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:             # <<<<<<<<<<<<<<
 *                 slope = 'right'
 *             elif slope > 0:
 */
        goto __pyx_L40;
      }

      /* "pyquant/cpeaks.pyx":659
 *             if slope < 0:
 *                 slope = 'right'
 *             elif slope > 0:             # <<<<<<<<<<<<<<
 *                 slope = 'left'
 *         if last_slope != -1:
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 659, __pyx_L1_error)
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":660
 *                 slope = 'right'
 *             elif slope > 0:
 *                 slope = 'left'             # <<<<<<<<<<<<<<
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:
 */
        __Pyx_INCREF(__pyx_n_s_left);
        __Pyx_DECREF_SET(__pyx_v_slope, __pyx_n_s_left);

        /* "pyquant/cpeaks.pyx":659
 *             if slope < 0:
 *                 slope = 'right'
 *             elif slope > 0:             # <<<<<<<<<<<<<<
 *                 slope = 'left'
 *         if last_slope != -1:
 */
      }
      __pyx_L40:;

      /* "pyquant/cpeaks.pyx":655
 *         grad = y[right:right+3]
 *         slope = None
 *         if len(grad) >= 2:             # <<<<<<<<<<<<<<
 *             slope = sum(np.sign(np.gradient(grad)))
 *             if slope < 0:
 */
    }

    /* "pyquant/cpeaks.pyx":661
 *             elif slope > 0:
 *                 slope = 'left'
 *         if last_slope != -1:             # <<<<<<<<<<<<<<
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 */
    __pyx_t_15 = PyObject_RichCompare(__pyx_v_last_slope, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 661, __pyx_L1_error)
    __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 661, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":662
 *                 slope = 'left'
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:             # <<<<<<<<<<<<<<
 *                 slope_shifts += 1
 *         last_slope = slope
 */
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_last_slope, __pyx_v_slope, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 662, __pyx_L1_error)
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 662, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      if (__pyx_t_19) {
      } else {
        __pyx_t_16 = __pyx_t_19;
        goto __pyx_L43_bool_binop_done;
      }
      __pyx_t_15 = PyObject_RichCompare(__pyx_v_slope, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 662, __pyx_L1_error)
      __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 662, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_16 = __pyx_t_19;
      __pyx_L43_bool_binop_done:;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":663
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1             # <<<<<<<<<<<<<<
 *         last_slope = slope
 *         if ishift == 'left' and ishift == slope:
 */
        __pyx_v_slope_shifts = (__pyx_v_slope_shifts + 1);

        /* "pyquant/cpeaks.pyx":662
 *                 slope = 'left'
 *         if last_slope != -1:
 *             if last_slope != slope and slope != None:             # <<<<<<<<<<<<<<
 *                 slope_shifts += 1
 *         last_slope = slope
 */
      }

      /* "pyquant/cpeaks.pyx":661
 *             elif slope > 0:
 *                 slope = 'left'
 *         if last_slope != -1:             # <<<<<<<<<<<<<<
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 */
    }

    /* "pyquant/cpeaks.pyx":664
 *             if last_slope != slope and slope != None:
 *                 slope_shifts += 1
 *         last_slope = slope             # <<<<<<<<<<<<<<
 *         if ishift == 'left' and ishift == slope:
 *             break
 */
    __Pyx_INCREF(__pyx_v_slope);
    __Pyx_DECREF_SET(__pyx_v_last_slope, __pyx_v_slope);

    /* "pyquant/cpeaks.pyx":665
 *                 slope_shifts += 1
 *         last_slope = slope
 *         if ishift == 'left' and ishift == slope:             # <<<<<<<<<<<<<<
 *             break
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 */
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_n_s_left, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 665, __pyx_L1_error)
    __pyx_t_20 = (__pyx_t_19 != 0);
    if (__pyx_t_20) {
    } else {
      __pyx_t_16 = __pyx_t_20;
      goto __pyx_L46_bool_binop_done;
    }
    __pyx_t_20 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_v_slope, Py_EQ)); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 665, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_20;
    __pyx_L46_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":666
 *         last_slope = slope
 *         if ishift == 'left' and ishift == slope:
 *             break             # <<<<<<<<<<<<<<
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 *             break
 */
      goto __pyx_L38_break;

      /* "pyquant/cpeaks.pyx":665
 *                 slope_shifts += 1
 *         last_slope = slope
 *         if ishift == 'left' and ishift == slope:             # <<<<<<<<<<<<<<
 *             break
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 */
    }

    /* "pyquant/cpeaks.pyx":667
 *         if ishift == 'left' and ishift == slope:
 *             break
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:             # <<<<<<<<<<<<<<
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):
 */
    __pyx_t_20 = (__Pyx_PyString_Equals(__pyx_v_ishift, __pyx_n_s_right, Py_EQ)); if (unlikely(__pyx_t_20 < 0)) __PYX_ERR(0, 667, __pyx_L1_error)
    __pyx_t_19 = (__pyx_t_20 != 0);
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L49_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_left, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 667, __pyx_L1_error)
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L49_bool_binop_done;
    }
    __pyx_t_19 = ((__pyx_v_slope_shifts > 1) != 0);
    __pyx_t_16 = __pyx_t_19;
    __pyx_L49_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":668
 *             break
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 *             break             # <<<<<<<<<<<<<<
 *         if val == 0 or (val > peak and slope != 'left'):
 *             if val > highest_val:
 */
      goto __pyx_L38_break;

      /* "pyquant/cpeaks.pyx":667
 *         if ishift == 'left' and ishift == slope:
 *             break
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:             # <<<<<<<<<<<<<<
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):
 */
    }

    /* "pyquant/cpeaks.pyx":669
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):             # <<<<<<<<<<<<<<
 *             if val > highest_val:
 *                 highest_val = val
 */
    __pyx_t_19 = ((__pyx_v_val == 0.0) != 0);
    if (!__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L53_bool_binop_done;
    }
    __pyx_t_19 = ((__pyx_v_val > __pyx_v_peak) != 0);
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L53_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_left, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 669, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_19;
    __pyx_L53_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":670
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):
 *             if val > highest_val:             # <<<<<<<<<<<<<<
 *                 highest_val = val
 *             if val == 0 or shift != 'right':
 */
      __pyx_t_16 = ((__pyx_v_val > __pyx_v_highest_val) != 0);
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":671
 *         if val == 0 or (val > peak and slope != 'left'):
 *             if val > highest_val:
 *                 highest_val = val             # <<<<<<<<<<<<<<
 *             if val == 0 or shift != 'right':
 *                 if val == 0:
 */
        __pyx_v_highest_val = __pyx_v_val;

        /* "pyquant/cpeaks.pyx":670
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):
 *             if val > highest_val:             # <<<<<<<<<<<<<<
 *                 highest_val = val
 *             if val == 0 or shift != 'right':
 */
      }

      /* "pyquant/cpeaks.pyx":672
 *             if val > highest_val:
 *                 highest_val = val
 *             if val == 0 or shift != 'right':             # <<<<<<<<<<<<<<
 *                 if val == 0:
 *                     right += 1
 */
      __pyx_t_19 = ((__pyx_v_val == 0.0) != 0);
      if (!__pyx_t_19) {
      } else {
        __pyx_t_16 = __pyx_t_19;
        goto __pyx_L58_bool_binop_done;
      }
      __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_shift, __pyx_n_s_right, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 672, __pyx_L1_error)
      __pyx_t_16 = __pyx_t_19;
      __pyx_L58_bool_binop_done:;
      if (__pyx_t_16) {

        /* "pyquant/cpeaks.pyx":673
 *                 highest_val = val
 *             if val == 0 or shift != 'right':
 *                 if val == 0:             # <<<<<<<<<<<<<<
 *                     right += 1
 *                 break
 */
        __pyx_t_16 = ((__pyx_v_val == 0.0) != 0);
        if (__pyx_t_16) {

          /* "pyquant/cpeaks.pyx":674
 *             if val == 0 or shift != 'right':
 *                 if val == 0:
 *                     right += 1             # <<<<<<<<<<<<<<
 *                 break
 *         elif shift == 'right' and slope != 'left':
 */
          __pyx_v_right = (__pyx_v_right + 1);

          /* "pyquant/cpeaks.pyx":673
 *                 highest_val = val
 *             if val == 0 or shift != 'right':
 *                 if val == 0:             # <<<<<<<<<<<<<<
 *                     right += 1
 *                 break
 */
        }

        /* "pyquant/cpeaks.pyx":675
 *                 if val == 0:
 *                     right += 1
 *                 break             # <<<<<<<<<<<<<<
 *         elif shift == 'right' and slope != 'left':
 *             shift = None
 */
        goto __pyx_L38_break;

        /* "pyquant/cpeaks.pyx":672
 *             if val > highest_val:
 *                 highest_val = val
 *             if val == 0 or shift != 'right':             # <<<<<<<<<<<<<<
 *                 if val == 0:
 *                     right += 1
 */
      }

      /* "pyquant/cpeaks.pyx":669
 *         if ishift == 'right' and slope == 'left' and slope_shifts > 1:
 *             break
 *         if val == 0 or (val > peak and slope != 'left'):             # <<<<<<<<<<<<<<
 *             if val > highest_val:
 *                 highest_val = val
 */
      goto __pyx_L52;
    }

    /* "pyquant/cpeaks.pyx":676
 *                     right += 1
 *                 break
 *         elif shift == 'right' and slope != 'left':             # <<<<<<<<<<<<<<
 *             shift = None
 *             peak = highest_val
 */
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_shift, __pyx_n_s_right, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 676, __pyx_L1_error)
    if (__pyx_t_19) {
    } else {
      __pyx_t_16 = __pyx_t_19;
      goto __pyx_L61_bool_binop_done;
    }
    __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_v_slope, __pyx_n_s_left, Py_NE)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 676, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_19;
    __pyx_L61_bool_binop_done:;
    if (__pyx_t_16) {

      /* "pyquant/cpeaks.pyx":677
 *                 break
 *         elif shift == 'right' and slope != 'left':
 *             shift = None             # <<<<<<<<<<<<<<
 *             peak = highest_val
 *     return left, right
 */
      __Pyx_INCREF(Py_None);
      __Pyx_DECREF_SET(__pyx_v_shift, Py_None);

      /* "pyquant/cpeaks.pyx":678
 *         elif shift == 'right' and slope != 'left':
 *             shift = None
 *             peak = highest_val             # <<<<<<<<<<<<<<
 *     return left, right
 * 
 */
      __pyx_v_peak = __pyx_v_highest_val;

      /* "pyquant/cpeaks.pyx":676
 *                     right += 1
 *                 break
 *         elif shift == 'right' and slope != 'left':             # <<<<<<<<<<<<<<
 *             shift = None
 *             peak = highest_val
 */
    }
    __pyx_L52:;
  }
  __pyx_L38_break:;

  /* "pyquant/cpeaks.pyx":679
 *             shift = None
 *             peak = highest_val
 *     return left, right             # <<<<<<<<<<<<<<
 * 
 * cpdef float get_ppm(float theoretical, float observed):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_left); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_right); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_13);
  __pyx_t_15 = 0;
  __pyx_t_13 = 0;
  __pyx_r = ((PyObject*)__pyx_t_14);
  __pyx_t_14 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":598
 *     return best_fit, best_rss
 * 
 * cdef tuple findPeak(np.ndarray[FLOAT_t, ndim=1] y, int srt):             # <<<<<<<<<<<<<<
 *     # check our SNR, if it's low, lessen our window
 *     cdef int left_offset = 1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  { 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_grad.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findPeak", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_grad.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_y.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_grad);
  __Pyx_XDECREF(__pyx_v_ishift);
  __Pyx_XDECREF(__pyx_v_shift);
  __Pyx_XDECREF(__pyx_v_last_slope);
  __Pyx_XDECREF(__pyx_v_slope);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":681
 *     return left, right
 * 
 * cpdef float get_ppm(float theoretical, float observed):             # <<<<<<<<<<<<<<
 *     return np.fabs(theoretical-observed)/theoretical
 * 
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_21get_ppm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static float __pyx_f_7pyquant_6cpeaks_get_ppm(float __pyx_v_theoretical, float __pyx_v_observed, CYTHON_UNUSED int __pyx_skip_dispatch) {
  float __pyx_r;
  __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;
  float __pyx_t_6;
  __Pyx_RefNannySetupContext("get_ppm", 0);

  /* "pyquant/cpeaks.pyx":682
 * 
 * cpdef float get_ppm(float theoretical, float observed):
 *     return np.fabs(theoretical-observed)/theoretical             # <<<<<<<<<<<<<<
 * 
 * cdef inline int within_tolerance(list array, float tolerance):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_fabs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyFloat_FromDouble((__pyx_v_theoretical - __pyx_v_observed)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_theoretical); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 682, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_6;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":681
 *     return left, right
 * 
 * cpdef float get_ppm(float theoretical, float observed):             # <<<<<<<<<<<<<<
 *     return np.fabs(theoretical-observed)/theoretical
 * 
 */

  /* 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_WriteUnraisable("pyquant.cpeaks.get_ppm", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_21get_ppm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_21get_ppm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  float __pyx_v_theoretical;
  float __pyx_v_observed;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_ppm (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_theoretical,&__pyx_n_s_observed,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_theoretical)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_observed)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_ppm", 1, 2, 2, 1); __PYX_ERR(0, 681, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_ppm") < 0)) __PYX_ERR(0, 681, __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_theoretical = __pyx_PyFloat_AsFloat(values[0]); if (unlikely((__pyx_v_theoretical == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L3_error)
    __pyx_v_observed = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_observed == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_ppm", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 681, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.get_ppm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_20get_ppm(__pyx_self, __pyx_v_theoretical, __pyx_v_observed);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_20get_ppm(CYTHON_UNUSED PyObject *__pyx_self, float __pyx_v_theoretical, float __pyx_v_observed) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_ppm", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_v_theoretical, __pyx_v_observed, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pyquant.cpeaks.get_ppm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":684
 *     return np.fabs(theoretical-observed)/theoretical
 * 
 * cdef inline int within_tolerance(list array, float tolerance):             # <<<<<<<<<<<<<<
 *     for i in array:
 *         if i[1] < tolerance:
 */

static CYTHON_INLINE int __pyx_f_7pyquant_6cpeaks_within_tolerance(PyObject *__pyx_v_array, float __pyx_v_tolerance) {
  PyObject *__pyx_v_i = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("within_tolerance", 0);

  /* "pyquant/cpeaks.pyx":685
 * 
 * cdef inline int within_tolerance(list array, float tolerance):
 *     for i in array:             # <<<<<<<<<<<<<<
 *         if i[1] < tolerance:
 *             return 1
 */
  if (unlikely(__pyx_v_array == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 685, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_array; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 685, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":686
 * cdef inline int within_tolerance(list array, float tolerance):
 *     for i in array:
 *         if i[1] < tolerance:             # <<<<<<<<<<<<<<
 *             return 1
 *     return 0
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_i, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tolerance); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_6) {

      /* "pyquant/cpeaks.pyx":687
 *     for i in array:
 *         if i[1] < tolerance:
 *             return 1             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
      __pyx_r = 1;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "pyquant/cpeaks.pyx":686
 * cdef inline int within_tolerance(list array, float tolerance):
 *     for i in array:
 *         if i[1] < tolerance:             # <<<<<<<<<<<<<<
 *             return 1
 *     return 0
 */
    }

    /* "pyquant/cpeaks.pyx":685
 * 
 * cdef inline int within_tolerance(list array, float tolerance):
 *     for i in array:             # <<<<<<<<<<<<<<
 *         if i[1] < tolerance:
 *             return 1
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":688
 *         if i[1] < tolerance:
 *             return 1
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":684
 *     return np.fabs(theoretical-observed)/theoretical
 * 
 * cdef inline int within_tolerance(list array, float tolerance):             # <<<<<<<<<<<<<<
 *     for i in array:
 *         if i[1] < tolerance:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("pyquant.cpeaks.within_tolerance", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_23findMicro(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7pyquant_6cpeaks_22findMicro[] = "\n        We want to find the boundaries of our isotopic clusters. Basically we search until our gradient\n        changes, this assumes it's roughly gaussian and there is little interference\n    ";
static PyMethodDef __pyx_mdef_7pyquant_6cpeaks_23findMicro = {"findMicro", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_23findMicro, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7pyquant_6cpeaks_22findMicro};
static PyObject *__pyx_pw_7pyquant_6cpeaks_23findMicro(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  PyObject *__pyx_v_pos = 0;
  PyObject *__pyx_v_ppm = 0;
  PyObject *__pyx_v_start_mz = 0;
  PyObject *__pyx_v_calc_start_mz = 0;
  PyObject *__pyx_v_isotope = 0;
  PyObject *__pyx_v_spacing = 0;
  CYTHON_UNUSED PyObject *__pyx_v_quant_method = 0;
  PyObject *__pyx_v_fragment_scan = 0;
  PyObject *__pyx_v_centroid = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("findMicro (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_ydata,&__pyx_n_s_pos,&__pyx_n_s_ppm,&__pyx_n_s_start_mz,&__pyx_n_s_calc_start_mz,&__pyx_n_s_isotope,&__pyx_n_s_spacing,&__pyx_n_s_quant_method,&__pyx_n_s_fragment_scan,&__pyx_n_s_centroid,0};
    PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);

    /* "pyquant/cpeaks.pyx":691
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,             # <<<<<<<<<<<<<<
 *                centroid=False):
 *     """
 */
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)Py_None);
    values[6] = ((PyObject *)__pyx_int_0);
    values[7] = ((PyObject *)__pyx_int_0);
    values[8] = ((PyObject *)__pyx_n_s_integrate);
    values[9] = ((PyObject *)Py_False);

    /* "pyquant/cpeaks.pyx":692
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):             # <<<<<<<<<<<<<<
 *     """
 *         We want to find the boundaries of our isotopic clusters. Basically we search until our gradient
 */
    values[10] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        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_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("findMicro", 0, 3, 11, 1); __PYX_ERR(0, 690, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("findMicro", 0, 3, 11, 2); __PYX_ERR(0, 690, __pyx_L3_error)
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ppm);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start_mz);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_calc_start_mz);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_isotope);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_spacing);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quant_method);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fragment_scan);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centroid);
          if (value) { values[10] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "findMicro") < 0)) __PYX_ERR(0, 690, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        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);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_ydata = ((PyArrayObject *)values[1]);
    __pyx_v_pos = values[2];
    __pyx_v_ppm = values[3];
    __pyx_v_start_mz = values[4];
    __pyx_v_calc_start_mz = values[5];
    __pyx_v_isotope = values[6];
    __pyx_v_spacing = values[7];
    __pyx_v_quant_method = values[8];
    __pyx_v_fragment_scan = values[9];
    __pyx_v_centroid = values[10];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("findMicro", 0, 3, 11, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 690, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.findMicro", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 690, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 690, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_22findMicro(__pyx_self, __pyx_v_xdata, __pyx_v_ydata, __pyx_v_pos, __pyx_v_ppm, __pyx_v_start_mz, __pyx_v_calc_start_mz, __pyx_v_isotope, __pyx_v_spacing, __pyx_v_quant_method, __pyx_v_fragment_scan, __pyx_v_centroid);

  /* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */

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

/* "pyquant/cpeaks.pyx":738
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):             # <<<<<<<<<<<<<<
 *                     sorted_peaks = sorted_peaks2
 *                 else:
 */

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_9findMicro_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_mdef_7pyquant_6cpeaks_9findMicro_lambda = {"lambda", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_9findMicro_lambda, METH_O, 0};
static PyObject *__pyx_pw_7pyquant_6cpeaks_9findMicro_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lambda (wrapper)", 0);
  __pyx_r = __pyx_lambda_funcdef_lambda(__pyx_self, ((PyObject *)__pyx_v_x));

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

static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x) {
  struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *__pyx_cur_scope;
  struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("lambda", 0);
  __pyx_outer_scope = (struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 738, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_tolerance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 738, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 738, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pyquant.cpeaks.findMicro.lambda", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */

static PyObject *__pyx_pf_7pyquant_6cpeaks_22findMicro(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, PyObject *__pyx_v_pos, PyObject *__pyx_v_ppm, PyObject *__pyx_v_start_mz, PyObject *__pyx_v_calc_start_mz, PyObject *__pyx_v_isotope, PyObject *__pyx_v_spacing, CYTHON_UNUSED PyObject *__pyx_v_quant_method, PyObject *__pyx_v_fragment_scan, PyObject *__pyx_v_centroid) {
  struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *__pyx_cur_scope;
  float __pyx_v_offset;
  float __pyx_v_int_val;
  float __pyx_v_peak_mean;
  PyArrayObject *__pyx_v_df_empty_index = 0;
  int __pyx_v_right;
  int __pyx_v_left;
  PyArrayObject *__pyx_v_new_x = 0;
  PyArrayObject *__pyx_v_new_y = 0;
  PyObject *__pyx_v_fit = NULL;
  PyObject *__pyx_v_error = NULL;
  PyObject *__pyx_v_peak = NULL;
  PyObject *__pyx_v_peaks = NULL;
  PyObject *__pyx_v_sorted_peaks = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_peak_residuals = NULL;
  PyObject *__pyx_v_sorted_peaks2 = NULL;
  PyObject *__pyx_v_ret_dict = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_v = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_df_empty_index;
  __Pyx_Buffer __pyx_pybuffer_df_empty_index;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_x;
  __Pyx_Buffer __pyx_pybuffer_new_x;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_new_y;
  __Pyx_Buffer __pyx_pybuffer_new_y;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  float __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyArrayObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  float __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  Py_ssize_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  PyArrayObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  PyObject *(*__pyx_t_25)(PyObject *);
  PyObject *(*__pyx_t_26)(PyObject *);
  PyObject *__pyx_t_27 = NULL;
  float __pyx_t_28;
  __Pyx_RefNannySetupContext("findMicro", 0);
  __pyx_cur_scope = (struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *)__pyx_tp_new_7pyquant_6cpeaks___pyx_scope_struct__findMicro(__pyx_ptype_7pyquant_6cpeaks___pyx_scope_struct__findMicro, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_INCREF(__pyx_v_start_mz);
  __pyx_pybuffer_df_empty_index.pybuffer.buf = NULL;
  __pyx_pybuffer_df_empty_index.refcount = 0;
  __pyx_pybuffernd_df_empty_index.data = NULL;
  __pyx_pybuffernd_df_empty_index.rcbuffer = &__pyx_pybuffer_df_empty_index;
  __pyx_pybuffer_new_x.pybuffer.buf = NULL;
  __pyx_pybuffer_new_x.refcount = 0;
  __pyx_pybuffernd_new_x.data = NULL;
  __pyx_pybuffernd_new_x.rcbuffer = &__pyx_pybuffer_new_x;
  __pyx_pybuffer_new_y.pybuffer.buf = NULL;
  __pyx_pybuffer_new_y.refcount = 0;
  __pyx_pybuffernd_new_y.data = NULL;
  __pyx_pybuffernd_new_y.rcbuffer = &__pyx_pybuffer_new_y;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 690, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 690, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":699
 *     # find the edges within our tolerance
 *     cdef float tolerance
 *     tolerance = ppm             # <<<<<<<<<<<<<<
 *     cdef float offset, int_val, peak_mean
 *     offset = spacing*isotope
 */
  __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_ppm); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 699, __pyx_L1_error)
  __pyx_cur_scope->__pyx_v_tolerance = __pyx_t_1;

  /* "pyquant/cpeaks.pyx":701
 *     tolerance = ppm
 *     cdef float offset, int_val, peak_mean
 *     offset = spacing*isotope             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] df_empty_index = xdata[ydata==0]
 *     cdef int right, left
 */
  __pyx_t_2 = PyNumber_Multiply(__pyx_v_spacing, __pyx_v_isotope); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_offset = __pyx_t_1;

  /* "pyquant/cpeaks.pyx":702
 *     cdef float offset, int_val, peak_mean
 *     offset = spacing*isotope
 *     cdef np.ndarray[FLOAT_t, ndim=1] df_empty_index = xdata[ydata==0]             # <<<<<<<<<<<<<<
 *     cdef int right, left
 *     cdef np.ndarray[FLOAT_t, ndim=1] new_x, new_y, lr
 */
  __pyx_t_2 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata), __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 702, __pyx_L1_error)
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 702, __pyx_L1_error)
  __pyx_t_4 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_df_empty_index = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 702, __pyx_L1_error)
    } else {__pyx_pybuffernd_df_empty_index.diminfo[0].strides = __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_df_empty_index.diminfo[0].shape = __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_4 = 0;
  __pyx_v_df_empty_index = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":705
 *     cdef int right, left
 *     cdef np.ndarray[FLOAT_t, ndim=1] new_x, new_y, lr
 *     if start_mz is None:             # <<<<<<<<<<<<<<
 *         start_mz = xdata[pos]
 *     fit = True
 */
  __pyx_t_5 = (__pyx_v_start_mz == Py_None);
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "pyquant/cpeaks.pyx":706
 *     cdef np.ndarray[FLOAT_t, ndim=1] new_x, new_y, lr
 *     if start_mz is None:
 *         start_mz = xdata[pos]             # <<<<<<<<<<<<<<
 *     fit = True
 *     if centroid:
 */
    __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_start_mz, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":705
 *     cdef int right, left
 *     cdef np.ndarray[FLOAT_t, ndim=1] new_x, new_y, lr
 *     if start_mz is None:             # <<<<<<<<<<<<<<
 *         start_mz = xdata[pos]
 *     fit = True
 */
  }

  /* "pyquant/cpeaks.pyx":707
 *     if start_mz is None:
 *         start_mz = xdata[pos]
 *     fit = True             # <<<<<<<<<<<<<<
 *     if centroid:
 *         int_val = ydata[pos]
 */
  __Pyx_INCREF(Py_True);
  __pyx_v_fit = Py_True;

  /* "pyquant/cpeaks.pyx":708
 *         start_mz = xdata[pos]
 *     fit = True
 *     if centroid:             # <<<<<<<<<<<<<<
 *         int_val = ydata[pos]
 *         left, right = pos-1, pos+1
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_centroid); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 708, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pyquant/cpeaks.pyx":709
 *     fit = True
 *     if centroid:
 *         int_val = ydata[pos]             # <<<<<<<<<<<<<<
 *         left, right = pos-1, pos+1
 *         error = get_ppm(start_mz+offset, xdata[pos])
 */
    __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_ydata), __pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 709, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 709, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_int_val = __pyx_t_1;

    /* "pyquant/cpeaks.pyx":710
 *     if centroid:
 *         int_val = ydata[pos]
 *         left, right = pos-1, pos+1             # <<<<<<<<<<<<<<
 *         error = get_ppm(start_mz+offset, xdata[pos])
 *         fit = np.abs(error) < tolerance
 */
    __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_pos, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_pos, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_left = __pyx_t_7;
    __pyx_v_right = __pyx_t_8;

    /* "pyquant/cpeaks.pyx":711
 *         int_val = ydata[pos]
 *         left, right = pos-1, pos+1
 *         error = get_ppm(start_mz+offset, xdata[pos])             # <<<<<<<<<<<<<<
 *         fit = np.abs(error) < tolerance
 *         peak = [int_val, xdata[pos], 0]
 */
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Add(__pyx_v_start_mz, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_1, __pyx_t_9, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_error = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":712
 *         left, right = pos-1, pos+1
 *         error = get_ppm(start_mz+offset, xdata[pos])
 *         fit = np.abs(error) < tolerance             # <<<<<<<<<<<<<<
 *         peak = [int_val, xdata[pos], 0]
 *     else:
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_abs); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_error); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_error);
      __Pyx_GIVEREF(__pyx_v_error);
      PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_error);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 712, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_tolerance); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = PyObject_RichCompare(__pyx_t_2, __pyx_t_10, Py_LT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF_SET(__pyx_v_fit, __pyx_t_11);
    __pyx_t_11 = 0;

    /* "pyquant/cpeaks.pyx":713
 *         error = get_ppm(start_mz+offset, xdata[pos])
 *         fit = np.abs(error) < tolerance
 *         peak = [int_val, xdata[pos], 0]             # <<<<<<<<<<<<<<
 *     else:
 *         if df_empty_index.size == 0 or not (df_empty_index[0] < xdata[pos] < df_empty_index[-1]):
 */
    __pyx_t_11 = PyFloat_FromDouble(__pyx_v_int_val); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_pos); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_11);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_10);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyList_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
    __pyx_t_11 = 0;
    __pyx_t_10 = 0;
    __pyx_v_peak = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":708
 *         start_mz = xdata[pos]
 *     fit = True
 *     if centroid:             # <<<<<<<<<<<<<<
 *         int_val = ydata[pos]
 *         left, right = pos-1, pos+1
 */
    goto __pyx_L4;
  }

  /* "pyquant/cpeaks.pyx":715
 *         peak = [int_val, xdata[pos], 0]
 *     else:
 *         if df_empty_index.size == 0 or not (df_empty_index[0] < xdata[pos] < df_empty_index[-1]):             # <<<<<<<<<<<<<<
 *             left = 0
 *             right = xdata.size
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_df_empty_index), __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (!__pyx_t_5) {
    } else {
      __pyx_t_6 = __pyx_t_5;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_12 = 0;
    __pyx_t_8 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_pybuffernd_df_empty_index.diminfo[0].shape;
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_8 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_df_empty_index.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      __PYX_ERR(0, 715, __pyx_L1_error)
    }
    __pyx_t_10 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_df_empty_index.diminfo[0].strides))); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = PyObject_RichCompare(__pyx_t_10, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 715, __pyx_L1_error)
    if (__Pyx_PyObject_IsTrue(__pyx_t_11)) {
      __Pyx_DECREF(__pyx_t_11);
      __pyx_t_13 = -1L;
      __pyx_t_8 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_pybuffernd_df_empty_index.diminfo[0].shape;
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_8 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_pybuffernd_df_empty_index.diminfo[0].shape)) __pyx_t_8 = 0;
      if (unlikely(__pyx_t_8 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_8);
        __PYX_ERR(0, 715, __pyx_L1_error)
      }
      __pyx_t_3 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_df_empty_index.diminfo[0].strides))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 715, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_11 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 715, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 715, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_14 = ((!__pyx_t_5) != 0);
    __pyx_t_6 = __pyx_t_14;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pyquant/cpeaks.pyx":716
 *     else:
 *         if df_empty_index.size == 0 or not (df_empty_index[0] < xdata[pos] < df_empty_index[-1]):
 *             left = 0             # <<<<<<<<<<<<<<
 *             right = xdata.size
 *         else:
 */
      __pyx_v_left = 0;

      /* "pyquant/cpeaks.pyx":717
 *         if df_empty_index.size == 0 or not (df_empty_index[0] < xdata[pos] < df_empty_index[-1]):
 *             left = 0
 *             right = xdata.size             # <<<<<<<<<<<<<<
 *         else:
 *             right = np.searchsorted(df_empty_index, xdata[pos])
 */
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_xdata), __pyx_n_s_size); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_v_right = __pyx_t_8;

      /* "pyquant/cpeaks.pyx":715
 *         peak = [int_val, xdata[pos], 0]
 *     else:
 *         if df_empty_index.size == 0 or not (df_empty_index[0] < xdata[pos] < df_empty_index[-1]):             # <<<<<<<<<<<<<<
 *             left = 0
 *             right = xdata.size
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":719
 *             right = xdata.size
 *         else:
 *             right = np.searchsorted(df_empty_index, xdata[pos])             # <<<<<<<<<<<<<<
 *             left = right-1
 *             left, right = (np.searchsorted(xdata, df_empty_index[left], side='left'),
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_v_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_15 = 1;
        }
      }
      __pyx_t_16 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_df_empty_index));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_df_empty_index));
      PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_15, ((PyObject *)__pyx_v_df_empty_index));
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_15, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_16, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 719, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_v_right = __pyx_t_8;

      /* "pyquant/cpeaks.pyx":720
 *         else:
 *             right = np.searchsorted(df_empty_index, xdata[pos])
 *             left = right-1             # <<<<<<<<<<<<<<
 *             left, right = (np.searchsorted(xdata, df_empty_index[left], side='left'),
 *                     np.searchsorted(xdata, df_empty_index[right]))
 */
      __pyx_v_left = (__pyx_v_right - 1);

      /* "pyquant/cpeaks.pyx":721
 *             right = np.searchsorted(df_empty_index, xdata[pos])
 *             left = right-1
 *             left, right = (np.searchsorted(xdata, df_empty_index[left], side='left'),             # <<<<<<<<<<<<<<
 *                     np.searchsorted(xdata, df_empty_index[right]))
 *             right += 1
 */
      __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_17 = __pyx_v_left;
      __pyx_t_8 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_df_empty_index.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_8 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_df_empty_index.diminfo[0].shape)) __pyx_t_8 = 0;
      if (unlikely(__pyx_t_8 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_8);
        __PYX_ERR(0, 721, __pyx_L1_error)
      }
      __pyx_t_11 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_df_empty_index.diminfo[0].strides))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
      PyTuple_SET_ITEM(__pyx_t_16, 0, ((PyObject *)__pyx_v_xdata));
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_side, __pyx_n_s_left) < 0) __PYX_ERR(0, 721, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_16, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 721, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":722
 *             left = right-1
 *             left, right = (np.searchsorted(xdata, df_empty_index[left], side='left'),
 *                     np.searchsorted(xdata, df_empty_index[right]))             # <<<<<<<<<<<<<<
 *             right += 1
 *         new_x = xdata[left:right]
 */
      __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_18 = __pyx_v_right;
      __pyx_t_7 = -1;
      if (__pyx_t_18 < 0) {
        __pyx_t_18 += __pyx_pybuffernd_df_empty_index.diminfo[0].shape;
        if (unlikely(__pyx_t_18 < 0)) __pyx_t_7 = 0;
      } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_df_empty_index.diminfo[0].shape)) __pyx_t_7 = 0;
      if (unlikely(__pyx_t_7 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_7);
        __PYX_ERR(0, 722, __pyx_L1_error)
      }
      __pyx_t_11 = PyFloat_FromDouble((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_df_empty_index.diminfo[0].strides))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_10 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_16))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_16);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_16, function);
          __pyx_t_15 = 1;
        }
      }
      __pyx_t_3 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_10) {
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); __pyx_t_10 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_15, ((PyObject *)__pyx_v_xdata));
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_15, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 722, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_left = __pyx_t_8;
      __pyx_v_right = __pyx_t_7;

      /* "pyquant/cpeaks.pyx":723
 *             left, right = (np.searchsorted(xdata, df_empty_index[left], side='left'),
 *                     np.searchsorted(xdata, df_empty_index[right]))
 *             right += 1             # <<<<<<<<<<<<<<
 *         new_x = xdata[left:right]
 *         new_y = ydata[left:right]
 */
      __pyx_v_right = (__pyx_v_right + 1);
    }
    __pyx_L5:;

    /* "pyquant/cpeaks.pyx":724
 *                     np.searchsorted(xdata, df_empty_index[right]))
 *             right += 1
 *         new_x = xdata[left:right]             # <<<<<<<<<<<<<<
 *         new_y = ydata[left:right]
 *         if new_y.sum() == new_y.max():
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_xdata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 724, __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, 724, __pyx_L1_error)
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_x.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_x.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_20, &__pyx_t_21, &__pyx_t_22);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_x.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_x, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_20); Py_XDECREF(__pyx_t_21); Py_XDECREF(__pyx_t_22);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_20, __pyx_t_21, __pyx_t_22);
        }
      }
      __pyx_pybuffernd_new_x.diminfo[0].strides = __pyx_pybuffernd_new_x.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_x.diminfo[0].shape = __pyx_pybuffernd_new_x.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 724, __pyx_L1_error)
    }
    __pyx_t_19 = 0;
    __pyx_v_new_x = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":725
 *             right += 1
 *         new_x = xdata[left:right]
 *         new_y = ydata[left:right]             # <<<<<<<<<<<<<<
 *         if new_y.sum() == new_y.max():
 *             peak_mean = new_x[np.where(new_y>0)][0]
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_ydata), __pyx_v_left, __pyx_v_right, NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 725, __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, 725, __pyx_L1_error)
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_y.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_y.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_22, &__pyx_t_21, &__pyx_t_20);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_new_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_new_y, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_22); Py_XDECREF(__pyx_t_21); Py_XDECREF(__pyx_t_20);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_22, __pyx_t_21, __pyx_t_20);
        }
      }
      __pyx_pybuffernd_new_y.diminfo[0].strides = __pyx_pybuffernd_new_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_new_y.diminfo[0].shape = __pyx_pybuffernd_new_y.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 725, __pyx_L1_error)
    }
    __pyx_t_19 = 0;
    __pyx_v_new_y = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":726
 *         new_x = xdata[left:right]
 *         new_y = ydata[left:right]
 *         if new_y.sum() == new_y.max():             # <<<<<<<<<<<<<<
 *             peak_mean = new_x[np.where(new_y>0)][0]
 *             peaks = (new_y.max(), peak_mean, 0)
 */
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_new_y), __pyx_n_s_sum); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 726, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_16))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_16);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_16, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_new_y), __pyx_n_s_max); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 726, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_11) {
      __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else {
      __pyx_t_16 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 726, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_t_16, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 726, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 726, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_6) {

      /* "pyquant/cpeaks.pyx":727
 *         new_y = ydata[left:right]
 *         if new_y.sum() == new_y.max():
 *             peak_mean = new_x[np.where(new_y>0)][0]             # <<<<<<<<<<<<<<
 *             peaks = (new_y.max(), peak_mean, 0)
 *             sorted_peaks = [(peaks, get_ppm(start_mz+offset, peak_mean))]
 */
      __pyx_t_16 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_where); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_16 = PyObject_RichCompare(((PyObject *)__pyx_v_new_y), __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 727, __pyx_L1_error)
      __pyx_t_11 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_new_x), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 727, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_peak_mean = __pyx_t_9;

      /* "pyquant/cpeaks.pyx":728
 *         if new_y.sum() == new_y.max():
 *             peak_mean = new_x[np.where(new_y>0)][0]
 *             peaks = (new_y.max(), peak_mean, 0)             # <<<<<<<<<<<<<<
 *             sorted_peaks = [(peaks, get_ppm(start_mz+offset, peak_mean))]
 *         else:
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_new_y), __pyx_n_s_max); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 728, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_10) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 728, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 728, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyFloat_FromDouble(__pyx_v_peak_mean); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 728, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 728, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_0);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_v_peaks = __pyx_t_10;
      __pyx_t_10 = 0;

      /* "pyquant/cpeaks.pyx":729
 *             peak_mean = new_x[np.where(new_y>0)][0]
 *             peaks = (new_y.max(), peak_mean, 0)
 *             sorted_peaks = [(peaks, get_ppm(start_mz+offset, peak_mean))]             # <<<<<<<<<<<<<<
 *         else:
 *             peaks, peak_residuals = findAllPeaks(new_x, new_y, min_dist=(new_x[1]-new_x[0])*2.0, peak_width_start=1)
 */
      __pyx_t_10 = PyFloat_FromDouble(__pyx_v_offset); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_2 = PyNumber_Add(__pyx_v_start_mz, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_9, __pyx_v_peak_mean, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_peaks);
      __Pyx_GIVEREF(__pyx_v_peaks);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_peaks);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_10);
      PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_v_sorted_peaks = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":726
 *         new_x = xdata[left:right]
 *         new_y = ydata[left:right]
 *         if new_y.sum() == new_y.max():             # <<<<<<<<<<<<<<
 *             peak_mean = new_x[np.where(new_y>0)][0]
 *             peaks = (new_y.max(), peak_mean, 0)
 */
      goto __pyx_L8;
    }

    /* "pyquant/cpeaks.pyx":731
 *             sorted_peaks = [(peaks, get_ppm(start_mz+offset, peak_mean))]
 *         else:
 *             peaks, peak_residuals = findAllPeaks(new_x, new_y, min_dist=(new_x[1]-new_x[0])*2.0, peak_width_start=1)             # <<<<<<<<<<<<<<
 *             sorted_peaks = sorted([(peaks[i*3:(i+1)*3], get_ppm(start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 * 
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_findAllPeaks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(((PyObject *)__pyx_v_new_x));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_new_x));
      PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_new_x));
      __Pyx_INCREF(((PyObject *)__pyx_v_new_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_new_y));
      PyTuple_SET_ITEM(__pyx_t_10, 1, ((PyObject *)__pyx_v_new_y));
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_23 = 1;
      __pyx_t_7 = -1;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_pybuffernd_new_x.diminfo[0].shape;
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_7 = 0;
      } else if (unlikely(__pyx_t_23 >= __pyx_pybuffernd_new_x.diminfo[0].shape)) __pyx_t_7 = 0;
      if (unlikely(__pyx_t_7 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_7);
        __PYX_ERR(0, 731, __pyx_L1_error)
      }
      __pyx_t_24 = 0;
      __pyx_t_7 = -1;
      if (__pyx_t_24 < 0) {
        __pyx_t_24 += __pyx_pybuffernd_new_x.diminfo[0].shape;
        if (unlikely(__pyx_t_24 < 0)) __pyx_t_7 = 0;
      } else if (unlikely(__pyx_t_24 >= __pyx_pybuffernd_new_x.diminfo[0].shape)) __pyx_t_7 = 0;
      if (unlikely(__pyx_t_7 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_7);
        __PYX_ERR(0, 731, __pyx_L1_error)
      }
      __pyx_t_16 = PyFloat_FromDouble((((*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_new_x.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_new_x.diminfo[0].strides)) - (*__Pyx_BufPtrStrided1d(__pyx_t_7pyquant_6cpeaks_FLOAT_t *, __pyx_pybuffernd_new_x.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_new_x.diminfo[0].strides))) * 2.0)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_min_dist, __pyx_t_16) < 0) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_peak_width_start, __pyx_int_1) < 0) __PYX_ERR(0, 731, __pyx_L1_error)
      __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, __pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 731, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_16))) || (PyList_CheckExact(__pyx_t_16))) {
        PyObject* sequence = __pyx_t_16;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 731, __pyx_L1_error)
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 731, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 731, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_2 = PyObject_GetIter(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_25 = Py_TYPE(__pyx_t_2)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_25(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_10 = __pyx_t_25(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_25(__pyx_t_2), 2) < 0) __PYX_ERR(0, 731, __pyx_L1_error)
        __pyx_t_25 = NULL;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_25 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 731, __pyx_L1_error)
        __pyx_L10_unpacking_done:;
      }
      __pyx_v_peaks = __pyx_t_3;
      __pyx_t_3 = 0;
      __pyx_v_peak_residuals = __pyx_t_10;
      __pyx_t_10 = 0;

      /* "pyquant/cpeaks.pyx":732
 *         else:
 *             peaks, peak_residuals = findAllPeaks(new_x, new_y, min_dist=(new_x[1]-new_x[0])*2.0, peak_width_start=1)
 *             sorted_peaks = sorted([(peaks[i*3:(i+1)*3], get_ppm(start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_16 = PyList_New(0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_INCREF(__pyx_int_0);
      __pyx_t_10 = __pyx_int_0;
      __pyx_t_3 = PyObject_GetItem(__pyx_v_peaks, __pyx_slice__24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_15 = 0;
        __pyx_t_26 = NULL;
      } else {
        __pyx_t_15 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_26 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 732, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_26)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 732, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_26(__pyx_t_2);
          if (unlikely(!__pyx_t_3)) {
            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, 732, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3);
        __pyx_t_3 = 0;
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_10);
        __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_10, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_10);
        __pyx_t_10 = __pyx_t_3;
        __pyx_t_3 = 0;
        __pyx_t_3 = PyNumber_Multiply(__pyx_v_i, __pyx_int_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_27 = PyNumber_Multiply(__pyx_t_11, __pyx_int_3); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyObject_GetSlice(__pyx_v_peaks, 0, 0, &__pyx_t_3, &__pyx_t_27, NULL, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
        __pyx_t_27 = PyFloat_FromDouble(__pyx_v_offset); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __pyx_t_3 = PyNumber_Add(__pyx_v_start_mz, __pyx_t_27); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
        __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_v); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 732, __pyx_L1_error)
        __pyx_t_3 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_9, __pyx_t_1, 0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_27 = PyTuple_New(2); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_27, 1, __pyx_t_3);
        __pyx_t_11 = 0;
        __pyx_t_3 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_16, (PyObject*)__pyx_t_27))) __PYX_ERR(0, 732, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_16);
      __pyx_t_16 = 0;
      __pyx_t_16 = PyDict_New(); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_27 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_27);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_key, __pyx_t_27) < 0) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
      __pyx_t_27 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_10, __pyx_t_16); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_27);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_v_sorted_peaks = __pyx_t_27;
      __pyx_t_27 = 0;
    }
    __pyx_L8:;

    /* "pyquant/cpeaks.pyx":735
 * 
 * 
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):             # <<<<<<<<<<<<<<
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 */
    __pyx_t_27 = PyObject_RichCompare(__pyx_v_fragment_scan, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_27); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 735, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_27); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    if (__pyx_t_14) {
    } else {
      __pyx_t_6 = __pyx_t_14;
      goto __pyx_L14_bool_binop_done;
    }
    if (!(likely(PyList_CheckExact(__pyx_v_sorted_peaks))||((__pyx_v_sorted_peaks) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_sorted_peaks)->tp_name), 0))) __PYX_ERR(0, 735, __pyx_L1_error)
    __pyx_t_14 = ((!(__pyx_f_7pyquant_6cpeaks_within_tolerance(((PyObject*)__pyx_v_sorted_peaks), __pyx_cur_scope->__pyx_v_tolerance) != 0)) != 0);
    __pyx_t_6 = __pyx_t_14;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pyquant/cpeaks.pyx":736
 * 
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):
 *             if calc_start_mz is not None:             # <<<<<<<<<<<<<<
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):
 */
      __pyx_t_6 = (__pyx_v_calc_start_mz != Py_None);
      __pyx_t_14 = (__pyx_t_6 != 0);
      if (__pyx_t_14) {

        /* "pyquant/cpeaks.pyx":737
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))             # <<<<<<<<<<<<<<
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):
 *                     sorted_peaks = sorted_peaks2
 */
        __pyx_t_27 = PyList_New(0); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_INCREF(__pyx_int_0);
        __pyx_t_16 = __pyx_int_0;
        __pyx_t_10 = PyObject_GetItem(__pyx_v_peaks, __pyx_slice__26); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
          __pyx_t_2 = __pyx_t_10; __Pyx_INCREF(__pyx_t_2); __pyx_t_15 = 0;
          __pyx_t_26 = NULL;
        } else {
          __pyx_t_15 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_26 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 737, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        for (;;) {
          if (likely(!__pyx_t_26)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_10 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_10); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 737, __pyx_L1_error)
              #else
              __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              #endif
            } else {
              if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_10); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 737, __pyx_L1_error)
              #else
              __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              #endif
            }
          } else {
            __pyx_t_10 = __pyx_t_26(__pyx_t_2);
            if (unlikely(!__pyx_t_10)) {
              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, 737, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_10);
          }
          __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_10);
          __pyx_t_10 = 0;
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_16);
          __pyx_t_10 = __Pyx_PyInt_AddObjC(__pyx_t_16, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_16);
          __pyx_t_16 = __pyx_t_10;
          __pyx_t_10 = 0;
          __pyx_t_10 = PyNumber_Multiply(__pyx_v_i, __pyx_int_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_11 = PyNumber_Multiply(__pyx_t_3, __pyx_int_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_peaks, 0, 0, &__pyx_t_10, &__pyx_t_11, NULL, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = PyFloat_FromDouble(__pyx_v_offset); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_10 = PyNumber_Add(__pyx_v_calc_start_mz, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_t_10); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_v_v); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 737, __pyx_L1_error)
          __pyx_t_10 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_1, __pyx_t_9, 0)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
          __pyx_t_3 = 0;
          __pyx_t_10 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_27, (PyObject*)__pyx_t_11))) __PYX_ERR(0, 737, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = PyTuple_New(1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_GIVEREF(__pyx_t_27);
        PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_27);
        __pyx_t_27 = 0;
        __pyx_t_27 = PyDict_New(); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (PyDict_SetItem(__pyx_t_27, __pyx_n_s_key, __pyx_t_11) < 0) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_16, __pyx_t_27); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 737, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
        __pyx_v_sorted_peaks2 = __pyx_t_11;
        __pyx_t_11 = 0;

        /* "pyquant/cpeaks.pyx":738
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):             # <<<<<<<<<<<<<<
 *                     sorted_peaks = sorted_peaks2
 *                 else:
 */
        __pyx_t_11 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7pyquant_6cpeaks_9findMicro_lambda, 0, __pyx_n_s_findMicro_locals_lambda, ((PyObject*)__pyx_cur_scope), __pyx_n_s_pyquant_cpeaks, __pyx_d, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 738, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_27 = PyTuple_New(2); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 738, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_27);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_27, 0, __pyx_t_11);
        __Pyx_INCREF(__pyx_v_sorted_peaks2);
        __Pyx_GIVEREF(__pyx_v_sorted_peaks2);
        PyTuple_SET_ITEM(__pyx_t_27, 1, __pyx_v_sorted_peaks2);
        __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_filter, __pyx_t_27, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 738, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 738, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (__pyx_t_14) {

          /* "pyquant/cpeaks.pyx":739
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):
 *                     sorted_peaks = sorted_peaks2             # <<<<<<<<<<<<<<
 *                 else:
 *                     fit = False
 */
          __Pyx_INCREF(__pyx_v_sorted_peaks2);
          __Pyx_DECREF_SET(__pyx_v_sorted_peaks, __pyx_v_sorted_peaks2);

          /* "pyquant/cpeaks.pyx":738
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):             # <<<<<<<<<<<<<<
 *                     sorted_peaks = sorted_peaks2
 *                 else:
 */
          goto __pyx_L19;
        }

        /* "pyquant/cpeaks.pyx":741
 *                     sorted_peaks = sorted_peaks2
 *                 else:
 *                     fit = False             # <<<<<<<<<<<<<<
 *             else:
 *                 fit = False
 */
        /*else*/ {
          __Pyx_INCREF(Py_False);
          __Pyx_DECREF_SET(__pyx_v_fit, Py_False);
        }
        __pyx_L19:;

        /* "pyquant/cpeaks.pyx":736
 * 
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):
 *             if calc_start_mz is not None:             # <<<<<<<<<<<<<<
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):
 */
        goto __pyx_L16;
      }

      /* "pyquant/cpeaks.pyx":743
 *                     fit = False
 *             else:
 *                 fit = False             # <<<<<<<<<<<<<<
 * 
 *         peak = list(sorted_peaks[0][0])
 */
      /*else*/ {
        __Pyx_INCREF(Py_False);
        __Pyx_DECREF_SET(__pyx_v_fit, Py_False);
      }
      __pyx_L16:;

      /* "pyquant/cpeaks.pyx":735
 * 
 * 
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):             # <<<<<<<<<<<<<<
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))
 */
    }

    /* "pyquant/cpeaks.pyx":745
 *                 fit = False
 * 
 *         peak = list(sorted_peaks[0][0])             # <<<<<<<<<<<<<<
 *         peak[0] *= new_y.max()
 * 
 */
    __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_sorted_peaks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_27 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PySequence_List(__pyx_t_27); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __pyx_v_peak = ((PyObject*)__pyx_t_11);
    __pyx_t_11 = 0;

    /* "pyquant/cpeaks.pyx":746
 * 
 *         peak = list(sorted_peaks[0][0])
 *         peak[0] *= new_y.max()             # <<<<<<<<<<<<<<
 * 
 *         int_val = gauss(new_x, peak[0], peak[1], peak[2]).sum()
 */
    __pyx_t_15 = 0;
    __pyx_t_11 = __Pyx_GetItemInt_List(__pyx_v_peak, __pyx_t_15, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_new_y), __pyx_n_s_max); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_16))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_16);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_16, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_27 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_2); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 746, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_27 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 746, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_27);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_16 = PyNumber_InPlaceMultiply(__pyx_t_11, __pyx_t_27); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    if (unlikely(__Pyx_SetItemInt(__pyx_v_peak, __pyx_t_15, __pyx_t_16, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 746, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;

    /* "pyquant/cpeaks.pyx":748
 *         peak[0] *= new_y.max()
 * 
 *         int_val = gauss(new_x, peak[0], peak[1], peak[2]).sum()             # <<<<<<<<<<<<<<
 *         if not fit:
 *             pass
 */
    __pyx_t_27 = __Pyx_GetItemInt_List(__pyx_v_peak, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __pyx_t_27 = __Pyx_GetItemInt_List(__pyx_v_peak, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __pyx_t_27 = __Pyx_GetItemInt_List(__pyx_v_peak, 2, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __pyx_t_28 = __pyx_PyFloat_AsFloat(__pyx_t_27); if (unlikely((__pyx_t_28 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __pyx_t_27 = ((PyObject *)__pyx_f_7pyquant_6cpeaks_gauss(((PyArrayObject *)__pyx_v_new_x), __pyx_t_9, __pyx_t_1, __pyx_t_28)); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_27, __pyx_n_s_sum); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    __pyx_t_27 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_11))) {
      __pyx_t_27 = PyMethod_GET_SELF(__pyx_t_11);
      if (likely(__pyx_t_27)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_27);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_11, function);
      }
    }
    if (__pyx_t_27) {
      __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_27); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 748, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
    } else {
      __pyx_t_16 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 748, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_28 = __pyx_PyFloat_AsFloat(__pyx_t_16); if (unlikely((__pyx_t_28 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_v_int_val = __pyx_t_28;

    /* "pyquant/cpeaks.pyx":749
 * 
 *         int_val = gauss(new_x, peak[0], peak[1], peak[2]).sum()
 *         if not fit:             # <<<<<<<<<<<<<<
 *             pass
 *         error = sorted_peaks[0][1]
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_fit); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 749, __pyx_L1_error)
    __pyx_t_6 = ((!__pyx_t_14) != 0);
    if (__pyx_t_6) {
    }

    /* "pyquant/cpeaks.pyx":751
 *         if not fit:
 *             pass
 *         error = sorted_peaks[0][1]             # <<<<<<<<<<<<<<
 *     ret_dict = {'int': int_val if fit or fragment_scan == True else 0, 'int2': int_val, 'bounds': (left, right), 'params': peak, 'error': error}
 *     return ret_dict
 */
    __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_sorted_peaks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 751, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_16, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 751, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_v_error = __pyx_t_11;
    __pyx_t_11 = 0;
  }
  __pyx_L4:;

  /* "pyquant/cpeaks.pyx":752
 *             pass
 *         error = sorted_peaks[0][1]
 *     ret_dict = {'int': int_val if fit or fragment_scan == True else 0, 'int2': int_val, 'bounds': (left, right), 'params': peak, 'error': error}             # <<<<<<<<<<<<<<
 *     return ret_dict
 * 
 */
  __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_fit); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 752, __pyx_L1_error)
  if (!__pyx_t_14) {
  } else {
    __pyx_t_6 = __pyx_t_14;
    goto __pyx_L21_bool_binop_done;
  }
  __pyx_t_27 = PyObject_RichCompare(__pyx_v_fragment_scan, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_27); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 752, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_27); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0;
  __pyx_t_6 = __pyx_t_14;
  __pyx_L21_bool_binop_done:;
  if (__pyx_t_6) {
    __pyx_t_27 = PyFloat_FromDouble(__pyx_v_int_val); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 752, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_27);
    __pyx_t_16 = __pyx_t_27;
    __pyx_t_27 = 0;
  } else {
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_16 = __pyx_int_0;
  }
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_int, __pyx_t_16) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = PyFloat_FromDouble(__pyx_v_int_val); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_int2, __pyx_t_16) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = __Pyx_PyInt_From_int(__pyx_v_left); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __pyx_t_27 = __Pyx_PyInt_From_int(__pyx_v_right); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_27);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_16);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16);
  __Pyx_GIVEREF(__pyx_t_27);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_27);
  __pyx_t_16 = 0;
  __pyx_t_27 = 0;
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_bounds, __pyx_t_2) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_params, __pyx_v_peak) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_error, __pyx_v_error) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  __pyx_v_ret_dict = ((PyObject*)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "pyquant/cpeaks.pyx":753
 *         error = sorted_peaks[0][1]
 *     ret_dict = {'int': int_val if fit or fragment_scan == True else 0, 'int2': int_val, 'bounds': (left, right), 'params': peak, 'error': error}
 *     return ret_dict             # <<<<<<<<<<<<<<
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret_dict);
  __pyx_r = __pyx_v_ret_dict;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_27);
  { 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_df_empty_index.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_x.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_y.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findMicro", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_df_empty_index.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_x.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_new_y.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_df_empty_index);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_x);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_y);
  __Pyx_XDECREF(__pyx_v_fit);
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_XDECREF(__pyx_v_peak);
  __Pyx_XDECREF(__pyx_v_peaks);
  __Pyx_XDECREF(__pyx_v_sorted_peaks);
  __Pyx_XDECREF(__pyx_v_peak_residuals);
  __Pyx_XDECREF(__pyx_v_sorted_peaks2);
  __Pyx_XDECREF(__pyx_v_ret_dict);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_start_mz);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":755
 *     return ret_dict
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     return array[find_nearest_index(array, value)]
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_25find_nearest(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_7pyquant_6cpeaks_25find_nearest = {"find_nearest", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_25find_nearest, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7pyquant_6cpeaks_25find_nearest(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_array = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_nearest (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_value,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_array)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_nearest", 1, 2, 2, 1); __PYX_ERR(0, 755, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_nearest") < 0)) __PYX_ERR(0, 755, __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_array = ((PyArrayObject *)values[0]);
    __pyx_v_value = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_nearest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 755, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) __PYX_ERR(0, 755, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_24find_nearest(__pyx_self, __pyx_v_array, __pyx_v_value);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_24find_nearest(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_array;
  __Pyx_Buffer __pyx_pybuffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("find_nearest", 0);
  __pyx_pybuffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_array.refcount = 0;
  __pyx_pybuffernd_array.data = NULL;
  __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 755, __pyx_L1_error)
  }
  __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":756
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     return array[find_nearest_index(array, value)]             # <<<<<<<<<<<<<<
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (__pyx_t_3) {
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_v_array));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_array));
  PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_array));
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_value);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_array), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":755
 *     return ret_dict
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     return array[find_nearest_index(array, value)]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  { 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_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":758
 *     return array[find_nearest_index(array, value)]
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_27find_nearest_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_7pyquant_6cpeaks_27find_nearest_index = {"find_nearest_index", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_27find_nearest_index, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7pyquant_6cpeaks_27find_nearest_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_array = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_nearest_index (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_value,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_array)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_nearest_index", 1, 2, 2, 1); __PYX_ERR(0, 758, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_nearest_index") < 0)) __PYX_ERR(0, 758, __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_array = ((PyArrayObject *)values[0]);
    __pyx_v_value = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_nearest_index", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 758, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) __PYX_ERR(0, 758, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_26find_nearest_index(__pyx_self, __pyx_v_array, __pyx_v_value);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_26find_nearest_index(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_idx = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_array;
  __Pyx_Buffer __pyx_pybuffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("find_nearest_index", 0);
  __pyx_pybuffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_array.refcount = 0;
  __pyx_pybuffernd_array.data = NULL;
  __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 758, __pyx_L1_error)
  }
  __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":759
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     idx = np.searchsorted(array, value, side="left")             # <<<<<<<<<<<<<<
 *     if idx == 0:
 *         return 0
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_array));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_array));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_array));
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_side, __pyx_n_s_left) < 0) __PYX_ERR(0, 759, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_idx = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":760
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:             # <<<<<<<<<<<<<<
 *         return 0
 *     elif idx == len(array):
 */
  __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_idx, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":761
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:
 *         return 0             # <<<<<<<<<<<<<<
 *     elif idx == len(array):
 *         return -1
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":760
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:             # <<<<<<<<<<<<<<
 *         return 0
 *     elif idx == len(array):
 */
  }

  /* "pyquant/cpeaks.pyx":762
 *     if idx == 0:
 *         return 0
 *     elif idx == len(array):             # <<<<<<<<<<<<<<
 *         return -1
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):
 */
  __pyx_t_6 = PyObject_Length(((PyObject *)__pyx_v_array)); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 762, __pyx_L1_error)
  __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":763
 *         return 0
 *     elif idx == len(array):
 *         return -1             # <<<<<<<<<<<<<<
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):
 *         return idx-1
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_neg_1);
    __pyx_r = __pyx_int_neg_1;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":762
 *     if idx == 0:
 *         return 0
 *     elif idx == len(array):             # <<<<<<<<<<<<<<
 *         return -1
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):
 */
  }

  /* "pyquant/cpeaks.pyx":764
 *     elif idx == len(array):
 *         return -1
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):             # <<<<<<<<<<<<<<
 *         return idx-1
 *     else:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_fabs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_array), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Subtract(__pyx_v_value, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 764, __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 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_fabs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyObject_GetItem(((PyObject *)__pyx_v_array), __pyx_v_idx); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Subtract(__pyx_v_value, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 764, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 764, __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_2);
    PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 764, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":765
 *         return -1
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):
 *         return idx-1             # <<<<<<<<<<<<<<
 *     else:
 *         return idx
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":764
 *     elif idx == len(array):
 *         return -1
 *     elif np.fabs(value - array[idx-1]) < np.fabs(value - array[idx]):             # <<<<<<<<<<<<<<
 *         return idx-1
 *     else:
 */
  }

  /* "pyquant/cpeaks.pyx":767
 *         return idx-1
 *     else:
 *         return idx             # <<<<<<<<<<<<<<
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_idx);
    __pyx_r = __pyx_v_idx;
    goto __pyx_L0;
  }

  /* "pyquant/cpeaks.pyx":758
 *     return array[find_nearest_index(array, value)]
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:
 */

  /* 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_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_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":769
 *         return idx
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_29find_nearest_indices(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_7pyquant_6cpeaks_29find_nearest_indices = {"find_nearest_indices", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_29find_nearest_indices, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7pyquant_6cpeaks_29find_nearest_indices(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_array = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_nearest_indices (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_value,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_array)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_nearest_indices", 1, 2, 2, 1); __PYX_ERR(0, 769, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_nearest_indices") < 0)) __PYX_ERR(0, 769, __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_array = ((PyArrayObject *)values[0]);
    __pyx_v_value = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_nearest_indices", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 769, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest_indices", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) __PYX_ERR(0, 769, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_28find_nearest_indices(__pyx_self, __pyx_v_array, __pyx_v_value);

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_28find_nearest_indices(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_indices = NULL;
  PyObject *__pyx_v_out = NULL;
  PyObject *__pyx_v_search_index = NULL;
  PyObject *__pyx_v_idx = NULL;
  PyObject *__pyx_v_search_value = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_array;
  __Pyx_Buffer __pyx_pybuffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_RefNannySetupContext("find_nearest_indices", 0);
  __pyx_pybuffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_array.refcount = 0;
  __pyx_pybuffernd_array.data = NULL;
  __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 769, __pyx_L1_error)
  }
  __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":770
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     indices = np.searchsorted(array, value, side="left")             # <<<<<<<<<<<<<<
 *     out = []
 *     for search_index, idx in enumerate(indices):
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_array));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_array));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_array));
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_side, __pyx_n_s_left) < 0) __PYX_ERR(0, 770, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_indices = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":771
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []             # <<<<<<<<<<<<<<
 *     for search_index, idx in enumerate(indices):
 *         search_value = value[search_index]
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_out = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":772
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 *     for search_index, idx in enumerate(indices):             # <<<<<<<<<<<<<<
 *         search_value = value[search_index]
 *         if idx == 0:
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_4 = __pyx_int_0;
  if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
    __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 772, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 772, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 772, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 772, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 772, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 772, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_3);
      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, 772, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_XDECREF_SET(__pyx_v_search_index, __pyx_t_4);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 772, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4);
    __pyx_t_4 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":773
 *     out = []
 *     for search_index, idx in enumerate(indices):
 *         search_value = value[search_index]             # <<<<<<<<<<<<<<
 *         if idx == 0:
 *             out.append(0)
 */
    __pyx_t_1 = PyObject_GetItem(__pyx_v_value, __pyx_v_search_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_search_value, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":774
 *     for search_index, idx in enumerate(indices):
 *         search_value = value[search_index]
 *         if idx == 0:             # <<<<<<<<<<<<<<
 *             out.append(0)
 *         elif idx == len(array):
 */
    __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_idx, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_7) {

      /* "pyquant/cpeaks.pyx":775
 *         search_value = value[search_index]
 *         if idx == 0:
 *             out.append(0)             # <<<<<<<<<<<<<<
 *         elif idx == len(array):
 *             out.append(-1)
 */
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_out, __pyx_int_0); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 775, __pyx_L1_error)

      /* "pyquant/cpeaks.pyx":774
 *     for search_index, idx in enumerate(indices):
 *         search_value = value[search_index]
 *         if idx == 0:             # <<<<<<<<<<<<<<
 *             out.append(0)
 *         elif idx == len(array):
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":776
 *         if idx == 0:
 *             out.append(0)
 *         elif idx == len(array):             # <<<<<<<<<<<<<<
 *             out.append(-1)
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):
 */
    __pyx_t_9 = PyObject_Length(((PyObject *)__pyx_v_array)); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 776, __pyx_L1_error)
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 776, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {

      /* "pyquant/cpeaks.pyx":777
 *             out.append(0)
 *         elif idx == len(array):
 *             out.append(-1)             # <<<<<<<<<<<<<<
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):
 *             out.append(idx-1)
 */
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_out, __pyx_int_neg_1); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 777, __pyx_L1_error)

      /* "pyquant/cpeaks.pyx":776
 *         if idx == 0:
 *             out.append(0)
 *         elif idx == len(array):             # <<<<<<<<<<<<<<
 *             out.append(-1)
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":778
 *         elif idx == len(array):
 *             out.append(-1)
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):             # <<<<<<<<<<<<<<
 *             out.append(idx-1)
 *         else:
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_fabs); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = PyObject_GetItem(((PyObject *)__pyx_v_array), __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Subtract(__pyx_v_search_value, __pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    if (!__pyx_t_11) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_fabs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyObject_GetItem(((PyObject *)__pyx_v_array), __pyx_v_idx); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_11 = PyNumber_Subtract(__pyx_v_search_value, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_12) {
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else {
      __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL;
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 778, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_10, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 778, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_7) {

      /* "pyquant/cpeaks.pyx":779
 *             out.append(-1)
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):
 *             out.append(idx-1)             # <<<<<<<<<<<<<<
 *         else:
 *             out.append(idx)
 */
      __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 779, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_out, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 779, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":778
 *         elif idx == len(array):
 *             out.append(-1)
 *         elif np.fabs(search_value - array[idx-1]) < np.fabs(search_value - array[idx]):             # <<<<<<<<<<<<<<
 *             out.append(idx-1)
 *         else:
 */
      goto __pyx_L5;
    }

    /* "pyquant/cpeaks.pyx":781
 *             out.append(idx-1)
 *         else:
 *             out.append(idx)             # <<<<<<<<<<<<<<
 *     return out
 * 
 */
    /*else*/ {
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_out, __pyx_v_idx); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 781, __pyx_L1_error)
    }
    __pyx_L5:;

    /* "pyquant/cpeaks.pyx":772
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 *     for search_index, idx in enumerate(indices):             # <<<<<<<<<<<<<<
 *         search_value = value[search_index]
 *         if idx == 0:
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pyquant/cpeaks.pyx":782
 *         else:
 *             out.append(idx)
 *     return out             # <<<<<<<<<<<<<<
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_out);
  __pyx_r = __pyx_v_out;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":769
 *         return idx
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 */

  /* 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_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.find_nearest_indices", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XDECREF(__pyx_v_out);
  __Pyx_XDECREF(__pyx_v_search_index);
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_XDECREF(__pyx_v_search_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pyquant/cpeaks.pyx":784
 *     return out
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,             # <<<<<<<<<<<<<<
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):
 */

static PyObject *__pyx_pw_7pyquant_6cpeaks_31findEnvelope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_7pyquant_6cpeaks_findEnvelope(PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7pyquant_6cpeaks_findEnvelope *__pyx_optional_args) {
  PyObject *__pyx_v_measured_mz = ((PyObject *)Py_None);
  PyObject *__pyx_v_theo_mz = ((PyObject *)Py_None);
  PyObject *__pyx_v_max_mz = ((PyObject *)Py_None);
  PyObject *__pyx_v_precursor_ppm = ((PyObject *)__pyx_int_5);
  PyObject *__pyx_v_isotope_ppm = ((PyObject *)__pyx_float_2_5);
  PyObject *__pyx_v_isotope_ppms = ((PyObject *)Py_None);
  PyObject *__pyx_v_charge = ((PyObject *)__pyx_int_2);
  PyObject *__pyx_v_debug = ((PyObject *)Py_False);
  PyObject *__pyx_v_isotope_offset = ((PyObject *)__pyx_int_0);
  PyObject *__pyx_v_isotopologue_limit = ((PyObject *)__pyx_int_neg_1);

  /* "pyquant/cpeaks.pyx":785
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,             # <<<<<<<<<<<<<<
 *                  centroid=False, contaminant_search=True):
 *     # returns the envelope of isotopic peaks as well as micro envelopes  of each individual cluster
 */
  PyObject *__pyx_v_theo_dist = ((PyObject *)Py_None);
  PyObject *__pyx_v_label = ((PyObject *)Py_None);
  PyObject *__pyx_v_skip_isotopes = ((PyObject *)Py_None);
  PyObject *__pyx_v_last_precursor = ((PyObject *)Py_None);
  PyObject *__pyx_v_quant_method = ((PyObject *)__pyx_n_s_integrate);
  PyObject *__pyx_v_reporter_mode = ((PyObject *)Py_False);
  PyObject *__pyx_v_fragment_scan = ((PyObject *)Py_False);

  /* "pyquant/cpeaks.pyx":786
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):             # <<<<<<<<<<<<<<
 *     # returns the envelope of isotopic peaks as well as micro envelopes  of each individual cluster
 *     cdef float spacing = NEUTRON/float(charge)
 */
  PyObject *__pyx_v_centroid = ((PyObject *)Py_False);
  PyObject *__pyx_v_contaminant_search = ((PyObject *)Py_True);
  float __pyx_v_spacing;
  float __pyx_v_tolerance;
  float __pyx_v_precursor_tolerance;
  PyObject *__pyx_v_start_mz = NULL;
  PyObject *__pyx_v_initial_mz = NULL;
  PyObject *__pyx_v_env_dict = NULL;
  PyObject *__pyx_v_micro_dict = NULL;
  PyObject *__pyx_v_ppm_dict = NULL;
  PyObject *__pyx_v_empty_dict = NULL;
  PyArrayObject *__pyx_v_non_empty = 0;
  PyObject *__pyx_v_first_mz = NULL;
  CYTHON_UNUSED long __pyx_v_attempts;
  PyObject *__pyx_v_isotope_index = NULL;
  int __pyx_v_use_theo;
  PyObject *__pyx_v_start_index = NULL;
  PyObject *__pyx_v_start_info = NULL;
  PyObject *__pyx_v_start_error = NULL;
  PyObject *__pyx_v_start = NULL;
  PyObject *__pyx_v_valid_locations2 = NULL;
  PyObject *__pyx_v_contaminant_bounds = NULL;
  PyObject *__pyx_v_contaminant_int = NULL;
  PyObject *__pyx_v_pos = NULL;
  PyObject *__pyx_v_offset = NULL;
  npy_intp __pyx_v_df_len;
  PyObject *__pyx_v_last_displacement = NULL;
  PyObject *__pyx_v_valid_locations = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_closest_contaminant = NULL;
  PyObject *__pyx_v_closest_contaminant_index = NULL;
  PyObject *__pyx_v_current_loc = NULL;
  PyObject *__pyx_v_displacement = NULL;
  PyObject *__pyx_v_valid_keys = NULL;
  PyObject *__pyx_v_best_locations = NULL;
  PyObject *__pyx_v_index = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_empty_index = NULL;
  PyObject *__pyx_v_micro_index = NULL;
  PyObject *__pyx_v_isotope_tolerance = NULL;
  PyObject *__pyx_v_micro_bounds = NULL;
  PyObject *__pyx_v_isotope_pattern = NULL;
  PyObject *__pyx_v_isotope_intensity = NULL;
  int __pyx_v_remove;
  PyObject *__pyx_v_j = NULL;
  int __pyx_v_shift;
  PyObject *__pyx_v_isotope_dict = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_non_empty;
  __Pyx_Buffer __pyx_pybuffer_non_empty;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  float __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  float __pyx_t_11;
  int __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  Py_ssize_t __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  __Pyx_RefNannySetupContext("findEnvelope", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_measured_mz = __pyx_optional_args->measured_mz;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_theo_mz = __pyx_optional_args->theo_mz;
        if (__pyx_optional_args->__pyx_n > 2) {
          __pyx_v_max_mz = __pyx_optional_args->max_mz;
          if (__pyx_optional_args->__pyx_n > 3) {
            __pyx_v_precursor_ppm = __pyx_optional_args->precursor_ppm;
            if (__pyx_optional_args->__pyx_n > 4) {
              __pyx_v_isotope_ppm = __pyx_optional_args->isotope_ppm;
              if (__pyx_optional_args->__pyx_n > 5) {
                __pyx_v_isotope_ppms = __pyx_optional_args->isotope_ppms;
                if (__pyx_optional_args->__pyx_n > 6) {
                  __pyx_v_charge = __pyx_optional_args->charge;
                  if (__pyx_optional_args->__pyx_n > 7) {
                    __pyx_v_debug = __pyx_optional_args->debug;
                    if (__pyx_optional_args->__pyx_n > 8) {
                      __pyx_v_isotope_offset = __pyx_optional_args->isotope_offset;
                      if (__pyx_optional_args->__pyx_n > 9) {
                        __pyx_v_isotopologue_limit = __pyx_optional_args->isotopologue_limit;
                        if (__pyx_optional_args->__pyx_n > 10) {
                          __pyx_v_theo_dist = __pyx_optional_args->theo_dist;
                          if (__pyx_optional_args->__pyx_n > 11) {
                            __pyx_v_label = __pyx_optional_args->label;
                            if (__pyx_optional_args->__pyx_n > 12) {
                              __pyx_v_skip_isotopes = __pyx_optional_args->skip_isotopes;
                              if (__pyx_optional_args->__pyx_n > 13) {
                                __pyx_v_last_precursor = __pyx_optional_args->last_precursor;
                                if (__pyx_optional_args->__pyx_n > 14) {
                                  __pyx_v_quant_method = __pyx_optional_args->quant_method;
                                  if (__pyx_optional_args->__pyx_n > 15) {
                                    __pyx_v_reporter_mode = __pyx_optional_args->reporter_mode;
                                    if (__pyx_optional_args->__pyx_n > 16) {
                                      __pyx_v_fragment_scan = __pyx_optional_args->fragment_scan;
                                      if (__pyx_optional_args->__pyx_n > 17) {
                                        __pyx_v_centroid = __pyx_optional_args->centroid;
                                        if (__pyx_optional_args->__pyx_n > 18) {
                                          __pyx_v_contaminant_search = __pyx_optional_args->contaminant_search;
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  __Pyx_INCREF(__pyx_v_theo_mz);
  __Pyx_INCREF(__pyx_v_max_mz);
  __Pyx_INCREF(__pyx_v_isotope_ppms);
  __Pyx_INCREF(__pyx_v_last_precursor);
  __pyx_pybuffer_non_empty.pybuffer.buf = NULL;
  __pyx_pybuffer_non_empty.refcount = 0;
  __pyx_pybuffernd_non_empty.data = NULL;
  __pyx_pybuffernd_non_empty.rcbuffer = &__pyx_pybuffer_non_empty;
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 784, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 784, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];

  /* "pyquant/cpeaks.pyx":788
 *                  centroid=False, contaminant_search=True):
 *     # returns the envelope of isotopic peaks as well as micro envelopes  of each individual cluster
 *     cdef float spacing = NEUTRON/float(charge)             # <<<<<<<<<<<<<<
 *     cdef float tolerance, precursor_tolerance
 *     start_mz = measured_mz if isotope_offset == 0 else measured_mz+isotope_offset*NEUTRON/float(charge)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEUTRON); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_charge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 788, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_spacing = __pyx_t_4;

  /* "pyquant/cpeaks.pyx":790
 *     cdef float spacing = NEUTRON/float(charge)
 *     cdef float tolerance, precursor_tolerance
 *     start_mz = measured_mz if isotope_offset == 0 else measured_mz+isotope_offset*NEUTRON/float(charge)             # <<<<<<<<<<<<<<
 *     initial_mz = start_mz
 *     if max_mz is not None:
 */
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_v_isotope_offset, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 790, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 790, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {
    __Pyx_INCREF(__pyx_v_measured_mz);
    __pyx_t_3 = __pyx_v_measured_mz;
  } else {
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEUTRON); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 790, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Multiply(__pyx_v_isotope_offset, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_charge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 790, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 790, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(__pyx_v_measured_mz, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 790, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_3 = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_v_start_mz = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":791
 *     cdef float tolerance, precursor_tolerance
 *     start_mz = measured_mz if isotope_offset == 0 else measured_mz+isotope_offset*NEUTRON/float(charge)
 *     initial_mz = start_mz             # <<<<<<<<<<<<<<
 *     if max_mz is not None:
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 */
  __Pyx_INCREF(__pyx_v_start_mz);
  __pyx_v_initial_mz = __pyx_v_start_mz;

  /* "pyquant/cpeaks.pyx":792
 *     start_mz = measured_mz if isotope_offset == 0 else measured_mz+isotope_offset*NEUTRON/float(charge)
 *     initial_mz = start_mz
 *     if max_mz is not None:             # <<<<<<<<<<<<<<
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 *     if isotope_ppms is None:
 */
  __pyx_t_5 = (__pyx_v_max_mz != Py_None);
  __pyx_t_7 = (__pyx_t_5 != 0);
  if (__pyx_t_7) {

    /* "pyquant/cpeaks.pyx":793
 *     initial_mz = start_mz
 *     if max_mz is not None:
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)             # <<<<<<<<<<<<<<
 *     if isotope_ppms is None:
 *         isotope_ppms = {}
 */
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_v_isotope_offset, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 793, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {
      __pyx_t_2 = PyFloat_FromDouble((__pyx_v_spacing * 0.9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyNumber_Subtract(__pyx_v_max_mz, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = __pyx_t_6;
      __pyx_t_6 = 0;
    } else {
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEUTRON); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = PyNumber_Multiply(__pyx_v_isotope_offset, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Multiply(__pyx_t_2, __pyx_float_0_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_charge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Add(__pyx_v_max_mz, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 793, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    }
    __Pyx_DECREF_SET(__pyx_v_max_mz, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":792
 *     start_mz = measured_mz if isotope_offset == 0 else measured_mz+isotope_offset*NEUTRON/float(charge)
 *     initial_mz = start_mz
 *     if max_mz is not None:             # <<<<<<<<<<<<<<
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 *     if isotope_ppms is None:
 */
  }

  /* "pyquant/cpeaks.pyx":794
 *     if max_mz is not None:
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 *     if isotope_ppms is None:             # <<<<<<<<<<<<<<
 *         isotope_ppms = {}
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0
 */
  __pyx_t_7 = (__pyx_v_isotope_ppms == Py_None);
  __pyx_t_5 = (__pyx_t_7 != 0);
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":795
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 *     if isotope_ppms is None:
 *         isotope_ppms = {}             # <<<<<<<<<<<<<<
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0
 *     env_dict, micro_dict, ppm_dict = OrderedDict(),OrderedDict(),OrderedDict()
 */
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_isotope_ppms, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":794
 *     if max_mz is not None:
 *         max_mz = max_mz-spacing*0.9 if isotope_offset == 0 else max_mz+isotope_offset*NEUTRON*0.9/float(charge)
 *     if isotope_ppms is None:             # <<<<<<<<<<<<<<
 *         isotope_ppms = {}
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0
 */
  }

  /* "pyquant/cpeaks.pyx":796
 *     if isotope_ppms is None:
 *         isotope_ppms = {}
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0             # <<<<<<<<<<<<<<
 *     env_dict, micro_dict, ppm_dict = OrderedDict(),OrderedDict(),OrderedDict()
 *     empty_dict = {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_isotope_ppms, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_8 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_1) {
    __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
  }
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_8, __pyx_int_0);
  __Pyx_INCREF(__pyx_v_precursor_ppm);
  __Pyx_GIVEREF(__pyx_v_precursor_ppm);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_8, __pyx_v_precursor_ppm);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyFloat_DivideObjC(__pyx_t_3, __pyx_float_1000000_0, 1000000.0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_tolerance = __pyx_t_4;

  /* "pyquant/cpeaks.pyx":797
 *         isotope_ppms = {}
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0
 *     env_dict, micro_dict, ppm_dict = OrderedDict(),OrderedDict(),OrderedDict()             # <<<<<<<<<<<<<<
 *     empty_dict = {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_6) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 797, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 797, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 797, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 797, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_9) {
    __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 797, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else {
    __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 797, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_env_dict = __pyx_t_2;
  __pyx_t_2 = 0;
  __pyx_v_micro_dict = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_ppm_dict = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":798
 *     tolerance = isotope_ppms.get(0, precursor_ppm)/1000000.0
 *     env_dict, micro_dict, ppm_dict = OrderedDict(),OrderedDict(),OrderedDict()
 *     empty_dict = {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}             # <<<<<<<<<<<<<<
 * 
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]
 */
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_envelope, __pyx_v_env_dict) < 0) __PYX_ERR(0, 798, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_micro_envelopes, __pyx_v_micro_dict) < 0) __PYX_ERR(0, 798, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_ppms, __pyx_v_ppm_dict) < 0) __PYX_ERR(0, 798, __pyx_L1_error)
  __pyx_v_empty_dict = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pyquant/cpeaks.pyx":800
 *     empty_dict = {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}
 * 
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]             # <<<<<<<<<<<<<<
 *     if len(non_empty) == 0:
 *         if debug:
 */
  __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_v_ydata), __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 800, __pyx_L1_error)
  __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_xdata), __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 800, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 800, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_non_empty.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_non_empty = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_non_empty.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 800, __pyx_L1_error)
    } else {__pyx_pybuffernd_non_empty.diminfo[0].strides = __pyx_pybuffernd_non_empty.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_non_empty.diminfo[0].shape = __pyx_pybuffernd_non_empty.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_non_empty = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":801
 * 
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]
 *     if len(non_empty) == 0:             # <<<<<<<<<<<<<<
 *         if debug:
 *             print('data is empty')
 */
  __pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_non_empty)); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 801, __pyx_L1_error)
  __pyx_t_5 = ((__pyx_t_8 == 0) != 0);
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":802
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]
 *     if len(non_empty) == 0:
 *         if debug:             # <<<<<<<<<<<<<<
 *             print('data is empty')
 *         return empty_dict
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 802, __pyx_L1_error)
    if (__pyx_t_5) {

      /* "pyquant/cpeaks.pyx":803
 *     if len(non_empty) == 0:
 *         if debug:
 *             print('data is empty')             # <<<<<<<<<<<<<<
 *         return empty_dict
 *     first_mz = find_nearest(non_empty, start_mz)
 */
      if (__Pyx_PrintOne(0, __pyx_kp_s_data_is_empty) < 0) __PYX_ERR(0, 803, __pyx_L1_error)

      /* "pyquant/cpeaks.pyx":802
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]
 *     if len(non_empty) == 0:
 *         if debug:             # <<<<<<<<<<<<<<
 *             print('data is empty')
 *         return empty_dict
 */
    }

    /* "pyquant/cpeaks.pyx":804
 *         if debug:
 *             print('data is empty')
 *         return empty_dict             # <<<<<<<<<<<<<<
 *     first_mz = find_nearest(non_empty, start_mz)
 *     attempts = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_empty_dict);
    __pyx_r = __pyx_v_empty_dict;
    goto __pyx_L0;

    /* "pyquant/cpeaks.pyx":801
 * 
 *     cdef np.ndarray[FLOAT_t] non_empty = xdata[ydata>0]
 *     if len(non_empty) == 0:             # <<<<<<<<<<<<<<
 *         if debug:
 *             print('data is empty')
 */
  }

  /* "pyquant/cpeaks.pyx":805
 *             print('data is empty')
 *         return empty_dict
 *     first_mz = find_nearest(non_empty, start_mz)             # <<<<<<<<<<<<<<
 *     attempts = 0
 * 
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
  PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, ((PyObject *)__pyx_v_non_empty));
  __Pyx_INCREF(__pyx_v_start_mz);
  __Pyx_GIVEREF(__pyx_v_start_mz);
  PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_v_start_mz);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_first_mz = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":806
 *         return empty_dict
 *     first_mz = find_nearest(non_empty, start_mz)
 *     attempts = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_attempts = 0;

  /* "pyquant/cpeaks.pyx":809
 * 
 * 
 *     isotope_index = 0             # <<<<<<<<<<<<<<
 *     use_theo = False
 *     # This is purposefully verbose to be more explicit
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_isotope_index = __pyx_int_0;

  /* "pyquant/cpeaks.pyx":810
 * 
 *     isotope_index = 0
 *     use_theo = False             # <<<<<<<<<<<<<<
 *     # This is purposefully verbose to be more explicit
 *     if reporter_mode == False and fragment_scan == False:
 */
  __pyx_v_use_theo = 0;

  /* "pyquant/cpeaks.pyx":812
 *     use_theo = False
 *     # This is purposefully verbose to be more explicit
 *     if reporter_mode == False and fragment_scan == False:             # <<<<<<<<<<<<<<
 *         while get_ppm(start_mz, first_mz) > tolerance:
 *             # let's try using our theoretical mass
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_reporter_mode, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 812, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L8_bool_binop_done;
  }
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_fragment_scan, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 812, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __pyx_t_7;
  __pyx_L8_bool_binop_done:;
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":813
 *     # This is purposefully verbose to be more explicit
 *     if reporter_mode == False and fragment_scan == False:
 *         while get_ppm(start_mz, first_mz) > tolerance:             # <<<<<<<<<<<<<<
 *             # let's try using our theoretical mass
 *             first_mz = find_nearest(non_empty, theo_mz)
 */
    while (1) {
      __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_v_start_mz); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 813, __pyx_L1_error)
      __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_v_first_mz); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 813, __pyx_L1_error)
      __pyx_t_5 = ((__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_4, __pyx_t_11, 0) > __pyx_v_tolerance) != 0);
      if (!__pyx_t_5) break;

      /* "pyquant/cpeaks.pyx":815
 *         while get_ppm(start_mz, first_mz) > tolerance:
 *             # let's try using our theoretical mass
 *             first_mz = find_nearest(non_empty, theo_mz)             # <<<<<<<<<<<<<<
 *             if get_ppm(theo_mz, first_mz) > tolerance:
 *                 # let's check our last boundary
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_8 = 1;
        }
      }
      __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, ((PyObject *)__pyx_v_non_empty));
      __Pyx_INCREF(__pyx_v_theo_mz);
      __Pyx_GIVEREF(__pyx_v_theo_mz);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_v_theo_mz);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 815, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF_SET(__pyx_v_first_mz, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pyquant/cpeaks.pyx":816
 *             # let's try using our theoretical mass
 *             first_mz = find_nearest(non_empty, theo_mz)
 *             if get_ppm(theo_mz, first_mz) > tolerance:             # <<<<<<<<<<<<<<
 *                 # let's check our last boundary
 *                 if last_precursor is not None:
 */
      __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_v_theo_mz); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 816, __pyx_L1_error)
      __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_v_first_mz); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 816, __pyx_L1_error)
      __pyx_t_5 = ((__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_11, __pyx_t_4, 0) > __pyx_v_tolerance) != 0);
      if (__pyx_t_5) {

        /* "pyquant/cpeaks.pyx":818
 *             if get_ppm(theo_mz, first_mz) > tolerance:
 *                 # let's check our last boundary
 *                 if last_precursor is not None:             # <<<<<<<<<<<<<<
 *                     first_mz = find_nearest(non_empty, last_precursor)
 *                     if get_ppm(last_precursor, first_mz) > tolerance:
 */
        __pyx_t_5 = (__pyx_v_last_precursor != Py_None);
        __pyx_t_7 = (__pyx_t_5 != 0);
        if (__pyx_t_7) {

          /* "pyquant/cpeaks.pyx":819
 *                 # let's check our last boundary
 *                 if last_precursor is not None:
 *                     first_mz = find_nearest(non_empty, last_precursor)             # <<<<<<<<<<<<<<
 *                     if get_ppm(last_precursor, first_mz) > tolerance:
 *                         # repeat all of that for the next isotopic index
 */
          __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 819, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_2 = NULL;
          __pyx_t_8 = 0;
          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_8 = 1;
            }
          }
          __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 819, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (__pyx_t_2) {
            __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
          PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, ((PyObject *)__pyx_v_non_empty));
          __Pyx_INCREF(__pyx_v_last_precursor);
          __Pyx_GIVEREF(__pyx_v_last_precursor);
          PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_v_last_precursor);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 819, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF_SET(__pyx_v_first_mz, __pyx_t_3);
          __pyx_t_3 = 0;

          /* "pyquant/cpeaks.pyx":820
 *                 if last_precursor is not None:
 *                     first_mz = find_nearest(non_empty, last_precursor)
 *                     if get_ppm(last_precursor, first_mz) > tolerance:             # <<<<<<<<<<<<<<
 *                         # repeat all of that for the next isotopic index
 *                         start_mz += spacing
 */
          __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_v_last_precursor); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 820, __pyx_L1_error)
          __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_v_first_mz); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 820, __pyx_L1_error)
          __pyx_t_7 = ((__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_4, __pyx_t_11, 0) > __pyx_v_tolerance) != 0);
          if (__pyx_t_7) {

            /* "pyquant/cpeaks.pyx":822
 *                     if get_ppm(last_precursor, first_mz) > tolerance:
 *                         # repeat all of that for the next isotopic index
 *                         start_mz += spacing             # <<<<<<<<<<<<<<
 *                         initial_mz += spacing
 *                         theo_mz += spacing
 */
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 822, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_start_mz, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 822, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF_SET(__pyx_v_start_mz, __pyx_t_6);
            __pyx_t_6 = 0;

            /* "pyquant/cpeaks.pyx":823
 *                         # repeat all of that for the next isotopic index
 *                         start_mz += spacing
 *                         initial_mz += spacing             # <<<<<<<<<<<<<<
 *                         theo_mz += spacing
 *                         last_precursor += spacing
 */
            __pyx_t_6 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 823, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_initial_mz, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF_SET(__pyx_v_initial_mz, __pyx_t_3);
            __pyx_t_3 = 0;

            /* "pyquant/cpeaks.pyx":824
 *                         start_mz += spacing
 *                         initial_mz += spacing
 *                         theo_mz += spacing             # <<<<<<<<<<<<<<
 *                         last_precursor += spacing
 *                         isotope_index += 1
 */
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 824, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_theo_mz, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 824, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF_SET(__pyx_v_theo_mz, __pyx_t_6);
            __pyx_t_6 = 0;

            /* "pyquant/cpeaks.pyx":825
 *                         initial_mz += spacing
 *                         theo_mz += spacing
 *                         last_precursor += spacing             # <<<<<<<<<<<<<<
 *                         isotope_index += 1
 *                     else:
 */
            __pyx_t_6 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 825, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_last_precursor, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 825, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF_SET(__pyx_v_last_precursor, __pyx_t_3);
            __pyx_t_3 = 0;

            /* "pyquant/cpeaks.pyx":826
 *                         theo_mz += spacing
 *                         last_precursor += spacing
 *                         isotope_index += 1             # <<<<<<<<<<<<<<
 *                     else:
 *                         start_mz = last_precursor
 */
            __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_isotope_index, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 826, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_3);
            __pyx_t_3 = 0;

            /* "pyquant/cpeaks.pyx":820
 *                 if last_precursor is not None:
 *                     first_mz = find_nearest(non_empty, last_precursor)
 *                     if get_ppm(last_precursor, first_mz) > tolerance:             # <<<<<<<<<<<<<<
 *                         # repeat all of that for the next isotopic index
 *                         start_mz += spacing
 */
            goto __pyx_L14;
          }

          /* "pyquant/cpeaks.pyx":828
 *                         isotope_index += 1
 *                     else:
 *                         start_mz = last_precursor             # <<<<<<<<<<<<<<
 *                         break
 *                 else:
 */
          /*else*/ {
            __Pyx_INCREF(__pyx_v_last_precursor);
            __Pyx_DECREF_SET(__pyx_v_start_mz, __pyx_v_last_precursor);

            /* "pyquant/cpeaks.pyx":829
 *                     else:
 *                         start_mz = last_precursor
 *                         break             # <<<<<<<<<<<<<<
 *                 else:
 *                     start_mz += spacing
 */
            goto __pyx_L11_break;
          }
          __pyx_L14:;

          /* "pyquant/cpeaks.pyx":818
 *             if get_ppm(theo_mz, first_mz) > tolerance:
 *                 # let's check our last boundary
 *                 if last_precursor is not None:             # <<<<<<<<<<<<<<
 *                     first_mz = find_nearest(non_empty, last_precursor)
 *                     if get_ppm(last_precursor, first_mz) > tolerance:
 */
          goto __pyx_L13;
        }

        /* "pyquant/cpeaks.pyx":831
 *                         break
 *                 else:
 *                     start_mz += spacing             # <<<<<<<<<<<<<<
 *                     theo_mz += spacing
 *                     initial_mz += spacing
 */
        /*else*/ {
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 831, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_start_mz, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 831, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF_SET(__pyx_v_start_mz, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "pyquant/cpeaks.pyx":832
 *                 else:
 *                     start_mz += spacing
 *                     theo_mz += spacing             # <<<<<<<<<<<<<<
 *                     initial_mz += spacing
 *                     isotope_index += 1
 */
          __pyx_t_6 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 832, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_theo_mz, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 832, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF_SET(__pyx_v_theo_mz, __pyx_t_3);
          __pyx_t_3 = 0;

          /* "pyquant/cpeaks.pyx":833
 *                     start_mz += spacing
 *                     theo_mz += spacing
 *                     initial_mz += spacing             # <<<<<<<<<<<<<<
 *                     isotope_index += 1
 *             else:
 */
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 833, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_initial_mz, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 833, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF_SET(__pyx_v_initial_mz, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "pyquant/cpeaks.pyx":834
 *                     theo_mz += spacing
 *                     initial_mz += spacing
 *                     isotope_index += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 use_theo = True
 */
          __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_isotope_index, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 834, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_6);
          __pyx_t_6 = 0;
        }
        __pyx_L13:;

        /* "pyquant/cpeaks.pyx":816
 *             # let's try using our theoretical mass
 *             first_mz = find_nearest(non_empty, theo_mz)
 *             if get_ppm(theo_mz, first_mz) > tolerance:             # <<<<<<<<<<<<<<
 *                 # let's check our last boundary
 *                 if last_precursor is not None:
 */
        goto __pyx_L12;
      }

      /* "pyquant/cpeaks.pyx":836
 *                     isotope_index += 1
 *             else:
 *                 use_theo = True             # <<<<<<<<<<<<<<
 *                 break
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 */
      /*else*/ {
        __pyx_v_use_theo = 1;

        /* "pyquant/cpeaks.pyx":837
 *             else:
 *                 use_theo = True
 *                 break             # <<<<<<<<<<<<<<
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):
 */
        goto __pyx_L11_break;
      }
      __pyx_L12:;

      /* "pyquant/cpeaks.pyx":838
 *                 use_theo = True
 *                 break
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0             # <<<<<<<<<<<<<<
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):
 *                 if debug:
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_isotope_ppms, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(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);
          __pyx_t_8 = 1;
        }
      }
      __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_isotope_index);
      __Pyx_GIVEREF(__pyx_v_isotope_index);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, __pyx_v_isotope_index);
      __Pyx_INCREF(__pyx_v_isotope_ppm);
      __Pyx_GIVEREF(__pyx_v_isotope_ppm);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_v_isotope_ppm);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyFloat_DivideObjC(__pyx_t_6, __pyx_float_1000000_0, 1000000.0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_tolerance = __pyx_t_11;

      /* "pyquant/cpeaks.pyx":839
 *                 break
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):             # <<<<<<<<<<<<<<
 *                 if debug:
 *                     print('unable to find start ion')
 */
      __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_isotope_index, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 839, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_5) {
      } else {
        __pyx_t_7 = __pyx_t_5;
        goto __pyx_L16_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_max_mz != Py_None);
      __pyx_t_12 = (__pyx_t_5 != 0);
      if (__pyx_t_12) {
      } else {
        __pyx_t_7 = __pyx_t_12;
        goto __pyx_L16_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_first_mz, __pyx_v_max_mz, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 839, __pyx_L1_error)
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __pyx_t_12;
      __pyx_L16_bool_binop_done:;
      if (__pyx_t_7) {

        /* "pyquant/cpeaks.pyx":840
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):
 *                 if debug:             # <<<<<<<<<<<<<<
 *                     print('unable to find start ion')
 *                 return empty_dict
 */
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 840, __pyx_L1_error)
        if (__pyx_t_7) {

          /* "pyquant/cpeaks.pyx":841
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):
 *                 if debug:
 *                     print('unable to find start ion')             # <<<<<<<<<<<<<<
 *                 return empty_dict
 * 
 */
          if (__Pyx_PrintOne(0, __pyx_kp_s_unable_to_find_start_ion) < 0) __PYX_ERR(0, 841, __pyx_L1_error)

          /* "pyquant/cpeaks.pyx":840
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):
 *                 if debug:             # <<<<<<<<<<<<<<
 *                     print('unable to find start ion')
 *                 return empty_dict
 */
        }

        /* "pyquant/cpeaks.pyx":842
 *                 if debug:
 *                     print('unable to find start ion')
 *                 return empty_dict             # <<<<<<<<<<<<<<
 * 
 *     precursor_tolerance = tolerance
 */
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(__pyx_v_empty_dict);
        __pyx_r = __pyx_v_empty_dict;
        goto __pyx_L0;

        /* "pyquant/cpeaks.pyx":839
 *                 break
 *             tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *             if isotope_index == 2 or (max_mz is not None and first_mz >= max_mz):             # <<<<<<<<<<<<<<
 *                 if debug:
 *                     print('unable to find start ion')
 */
      }
    }
    __pyx_L11_break:;

    /* "pyquant/cpeaks.pyx":812
 *     use_theo = False
 *     # This is purposefully verbose to be more explicit
 *     if reporter_mode == False and fragment_scan == False:             # <<<<<<<<<<<<<<
 *         while get_ppm(start_mz, first_mz) > tolerance:
 *             # let's try using our theoretical mass
 */
  }

  /* "pyquant/cpeaks.pyx":844
 *                 return empty_dict
 * 
 *     precursor_tolerance = tolerance             # <<<<<<<<<<<<<<
 * 
 *     isotope_index += isotope_offset
 */
  __pyx_v_precursor_tolerance = __pyx_v_tolerance;

  /* "pyquant/cpeaks.pyx":846
 *     precursor_tolerance = tolerance
 * 
 *     isotope_index += isotope_offset             # <<<<<<<<<<<<<<
 *     start_index = find_nearest_index(xdata, first_mz)
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,
 */
  __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_isotope_index, __pyx_v_isotope_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 846, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":847
 * 
 *     isotope_index += isotope_offset
 *     start_index = find_nearest_index(xdata, first_mz)             # <<<<<<<<<<<<<<
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,
 *      quant_method=quant_method, fragment_scan=fragment_scan, centroid=centroid)
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, ((PyObject *)__pyx_v_xdata));
  __Pyx_INCREF(__pyx_v_first_mz);
  __Pyx_GIVEREF(__pyx_v_first_mz);
  PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_v_first_mz);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_start_index = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pyquant/cpeaks.pyx":848
 *     isotope_index += isotope_offset
 *     start_index = find_nearest_index(xdata, first_mz)
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,             # <<<<<<<<<<<<<<
 *      quant_method=quant_method, fragment_scan=fragment_scan, centroid=centroid)
 *     start_error = start_info['error']
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_findMicro); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
  PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_xdata));
  __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
  PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_ydata));
  __Pyx_INCREF(__pyx_v_start_index);
  __Pyx_GIVEREF(__pyx_v_start_index);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_start_index);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyFloat_FromDouble(__pyx_v_tolerance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ppm, __pyx_t_2) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start_mz, __pyx_v_start_mz) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_calc_start_mz, __pyx_v_theo_mz) < 0) __PYX_ERR(0, 848, __pyx_L1_error)

  /* "pyquant/cpeaks.pyx":849
 *     start_index = find_nearest_index(xdata, first_mz)
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,
 *      quant_method=quant_method, fragment_scan=fragment_scan, centroid=centroid)             # <<<<<<<<<<<<<<
 *     start_error = start_info['error']
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_quant_method, __pyx_v_quant_method) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fragment_scan, __pyx_v_fragment_scan) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_centroid, __pyx_v_centroid) < 0) __PYX_ERR(0, 848, __pyx_L1_error)

  /* "pyquant/cpeaks.pyx":848
 *     isotope_index += isotope_offset
 *     start_index = find_nearest_index(xdata, first_mz)
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,             # <<<<<<<<<<<<<<
 *      quant_method=quant_method, fragment_scan=fragment_scan, centroid=centroid)
 *     start_error = start_info['error']
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_start_info = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":850
 *     start_info = findMicro(xdata, ydata, start_index, ppm=tolerance, start_mz=start_mz, calc_start_mz=theo_mz,
 *      quant_method=quant_method, fragment_scan=fragment_scan, centroid=centroid)
 *     start_error = start_info['error']             # <<<<<<<<<<<<<<
 * 
 *     if 'params' in start_info:
 */
  __pyx_t_2 = PyObject_GetItem(__pyx_v_start_info, __pyx_n_s_error); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_start_error = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":852
 *     start_error = start_info['error']
 * 
 *     if 'params' in start_info:             # <<<<<<<<<<<<<<
 *         if fragment_scan == False and start_info['error'] > tolerance:
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz
 */
  __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_params, __pyx_v_start_info, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 852, __pyx_L1_error)
  __pyx_t_12 = (__pyx_t_7 != 0);
  if (__pyx_t_12) {

    /* "pyquant/cpeaks.pyx":853
 * 
 *     if 'params' in start_info:
 *         if fragment_scan == False and start_info['error'] > tolerance:             # <<<<<<<<<<<<<<
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz
 *         else:
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_fragment_scan, Py_False, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 853, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {
    } else {
      __pyx_t_12 = __pyx_t_7;
      goto __pyx_L22_bool_binop_done;
    }
    __pyx_t_2 = PyObject_GetItem(__pyx_v_start_info, __pyx_n_s_error); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tolerance); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_12 = __pyx_t_7;
    __pyx_L22_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":854
 *     if 'params' in start_info:
 *         if fragment_scan == False and start_info['error'] > tolerance:
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz             # <<<<<<<<<<<<<<
 *         else:
 *             start = start_info['params'][1]
 */
      __pyx_t_12 = (__pyx_v_last_precursor != Py_None);
      if ((__pyx_t_12 != 0)) {
        __Pyx_INCREF(__pyx_v_last_precursor);
        __pyx_t_6 = __pyx_v_last_precursor;
      } else {
        if ((__pyx_v_use_theo != 0)) {
          __Pyx_INCREF(__pyx_v_theo_mz);
          __pyx_t_1 = __pyx_v_theo_mz;
        } else {
          __Pyx_INCREF(__pyx_v_start_mz);
          __pyx_t_1 = __pyx_v_start_mz;
        }
        __pyx_t_6 = __pyx_t_1;
        __pyx_t_1 = 0;
      }
      __pyx_v_start = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pyquant/cpeaks.pyx":853
 * 
 *     if 'params' in start_info:
 *         if fragment_scan == False and start_info['error'] > tolerance:             # <<<<<<<<<<<<<<
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz
 *         else:
 */
      goto __pyx_L21;
    }

    /* "pyquant/cpeaks.pyx":856
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz
 *         else:
 *             start = start_info['params'][1]             # <<<<<<<<<<<<<<
 *     else:
 *         if debug:
 */
    /*else*/ {
      __pyx_t_6 = PyObject_GetItem(__pyx_v_start_info, __pyx_n_s_params); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 856, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_start = __pyx_t_1;
      __pyx_t_1 = 0;
    }
    __pyx_L21:;

    /* "pyquant/cpeaks.pyx":852
 *     start_error = start_info['error']
 * 
 *     if 'params' in start_info:             # <<<<<<<<<<<<<<
 *         if fragment_scan == False and start_info['error'] > tolerance:
 *             start = last_precursor if last_precursor is not None else theo_mz if use_theo else start_mz
 */
    goto __pyx_L20;
  }

  /* "pyquant/cpeaks.pyx":858
 *             start = start_info['params'][1]
 *     else:
 *         if debug:             # <<<<<<<<<<<<<<
 *             print('empty start info', start_info)
 *         return empty_dict
 */
  /*else*/ {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 858, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":859
 *     else:
 *         if debug:
 *             print('empty start info', start_info)             # <<<<<<<<<<<<<<
 *         return empty_dict
 * 
 */
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_kp_s_empty_start_info);
      __Pyx_GIVEREF(__pyx_kp_s_empty_start_info);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s_empty_start_info);
      __Pyx_INCREF(__pyx_v_start_info);
      __Pyx_GIVEREF(__pyx_v_start_info);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start_info);
      if (__Pyx_PrintOne(0, __pyx_t_1) < 0) __PYX_ERR(0, 859, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":858
 *             start = start_info['params'][1]
 *     else:
 *         if debug:             # <<<<<<<<<<<<<<
 *             print('empty start info', start_info)
 *         return empty_dict
 */
    }

    /* "pyquant/cpeaks.pyx":860
 *         if debug:
 *             print('empty start info', start_info)
 *         return empty_dict             # <<<<<<<<<<<<<<
 * 
 *     valid_locations2 = OrderedDict()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_empty_dict);
    __pyx_r = __pyx_v_empty_dict;
    goto __pyx_L0;
  }
  __pyx_L20:;

  /* "pyquant/cpeaks.pyx":862
 *         return empty_dict
 * 
 *     valid_locations2 = OrderedDict()             # <<<<<<<<<<<<<<
 *     valid_locations2[isotope_index] = [(0, start, find_nearest_index(non_empty, start))]
 *     contaminant_bounds = {}
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_valid_locations2 = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":863
 * 
 *     valid_locations2 = OrderedDict()
 *     valid_locations2[isotope_index] = [(0, start, find_nearest_index(non_empty, start))]             # <<<<<<<<<<<<<<
 *     contaminant_bounds = {}
 *     contaminant_int = 0.
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  __pyx_t_3 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
  PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_8, ((PyObject *)__pyx_v_non_empty));
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_8, __pyx_v_start);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_int_0);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_valid_locations2, __pyx_v_isotope_index, __pyx_t_1) < 0)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":864
 *     valid_locations2 = OrderedDict()
 *     valid_locations2[isotope_index] = [(0, start, find_nearest_index(non_empty, start))]
 *     contaminant_bounds = {}             # <<<<<<<<<<<<<<
 *     contaminant_int = 0.
 * 
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 864, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_contaminant_bounds = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":865
 *     valid_locations2[isotope_index] = [(0, start, find_nearest_index(non_empty, start))]
 *     contaminant_bounds = {}
 *     contaminant_int = 0.             # <<<<<<<<<<<<<<
 * 
 *     if not reporter_mode and (isotopologue_limit == -1 or len(valid_locations2) < isotopologue_limit):
 */
  __Pyx_INCREF(__pyx_float_0_);
  __pyx_v_contaminant_int = __pyx_float_0_;

  /* "pyquant/cpeaks.pyx":867
 *     contaminant_int = 0.
 * 
 *     if not reporter_mode and (isotopologue_limit == -1 or len(valid_locations2) < isotopologue_limit):             # <<<<<<<<<<<<<<
 *         isotope_index += 1
 *         pos = find_nearest_index(non_empty, start)+1
 */
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_reporter_mode); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 867, __pyx_L1_error)
  __pyx_t_5 = ((!__pyx_t_7) != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_12 = __pyx_t_5;
    goto __pyx_L26_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_isotopologue_limit, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_5) {
  } else {
    __pyx_t_12 = __pyx_t_5;
    goto __pyx_L26_bool_binop_done;
  }
  __pyx_t_8 = PyObject_Length(__pyx_v_valid_locations2); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 867, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_v_isotopologue_limit, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_12 = __pyx_t_5;
  __pyx_L26_bool_binop_done:;
  if (__pyx_t_12) {

    /* "pyquant/cpeaks.pyx":868
 * 
 *     if not reporter_mode and (isotopologue_limit == -1 or len(valid_locations2) < isotopologue_limit):
 *         isotope_index += 1             # <<<<<<<<<<<<<<
 *         pos = find_nearest_index(non_empty, start)+1
 *         offset = isotope_index*spacing
 */
    __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_isotope_index, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 868, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pyquant/cpeaks.pyx":869
 *     if not reporter_mode and (isotopologue_limit == -1 or len(valid_locations2) < isotopologue_limit):
 *         isotope_index += 1
 *         pos = find_nearest_index(non_empty, start)+1             # <<<<<<<<<<<<<<
 *         offset = isotope_index*spacing
 *         df_len = non_empty.shape[0]
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_8 = 1;
      }
    }
    __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, ((PyObject *)__pyx_v_non_empty));
    __Pyx_INCREF(__pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_v_start);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 869, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_pos = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":870
 *         isotope_index += 1
 *         pos = find_nearest_index(non_empty, start)+1
 *         offset = isotope_index*spacing             # <<<<<<<<<<<<<<
 *         df_len = non_empty.shape[0]
 *         last_displacement = None
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 870, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyNumber_Multiply(__pyx_v_isotope_index, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 870, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_offset = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pyquant/cpeaks.pyx":871
 *         pos = find_nearest_index(non_empty, start)+1
 *         offset = isotope_index*spacing
 *         df_len = non_empty.shape[0]             # <<<<<<<<<<<<<<
 *         last_displacement = None
 *         valid_locations = []
 */
    __pyx_v_df_len = (__pyx_v_non_empty->dimensions[0]);

    /* "pyquant/cpeaks.pyx":872
 *         offset = isotope_index*spacing
 *         df_len = non_empty.shape[0]
 *         last_displacement = None             # <<<<<<<<<<<<<<
 *         valid_locations = []
 * 
 */
    __Pyx_INCREF(Py_None);
    __pyx_v_last_displacement = Py_None;

    /* "pyquant/cpeaks.pyx":873
 *         df_len = non_empty.shape[0]
 *         last_displacement = None
 *         valid_locations = []             # <<<<<<<<<<<<<<
 * 
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 */
    __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 873, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_valid_locations = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "pyquant/cpeaks.pyx":876
 * 
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 *         if contaminant_search:             # <<<<<<<<<<<<<<
 *             for i in xrange(2, 4):
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 */
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_contaminant_search); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 876, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":877
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 *         if contaminant_search:
 *             for i in xrange(2, 4):             # <<<<<<<<<<<<<<
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
        __pyx_t_1 = __pyx_t_6; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0;
        __pyx_t_13 = NULL;
      } else {
        __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 877, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 877, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (;;) {
        if (likely(!__pyx_t_13)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 877, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          } else {
            if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 877, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          }
        } else {
          __pyx_t_6 = __pyx_t_13(__pyx_t_1);
          if (unlikely(!__pyx_t_6)) {
            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, 877, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pyquant/cpeaks.pyx":878
 *         if contaminant_search:
 *             for i in xrange(2, 4):
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))             # <<<<<<<<<<<<<<
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,
 */
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEUTRON); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = __Pyx_PyNumber_Float(__pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_14 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = PyNumber_Subtract(__pyx_v_start, __pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = NULL;
        __pyx_t_15 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_15 = 1;
          }
        }
        __pyx_t_3 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_non_empty));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_non_empty));
        PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_15, ((PyObject *)__pyx_v_non_empty));
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_15, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 878, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_closest_contaminant, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pyquant/cpeaks.pyx":879
 *             for i in xrange(2, 4):
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)             # <<<<<<<<<<<<<<
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 */
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 879, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = NULL;
        __pyx_t_15 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_15 = 1;
          }
        }
        __pyx_t_9 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 879, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_15, ((PyObject *)__pyx_v_xdata));
        __Pyx_INCREF(__pyx_v_closest_contaminant);
        __Pyx_GIVEREF(__pyx_v_closest_contaminant);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_15, __pyx_v_closest_contaminant);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 879, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_closest_contaminant_index, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pyquant/cpeaks.pyx":880
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,             # <<<<<<<<<<<<<<
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)
 */
        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_findMicro); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_xdata));
        __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
        PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_ydata));
        __Pyx_INCREF(__pyx_v_closest_contaminant_index);
        __Pyx_GIVEREF(__pyx_v_closest_contaminant_index);
        PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_closest_contaminant_index);
        __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = PyFloat_FromDouble(__pyx_v_precursor_tolerance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_ppm, __pyx_t_3) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pyquant/cpeaks.pyx":881
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),             # <<<<<<<<<<<<<<
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:
 */
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_calc_start_mz, __pyx_v_start) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_start_mz, __pyx_v_start) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_isotope, __pyx_int_neg_1) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEUTRON); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 881, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_14 = __Pyx_PyNumber_Float(__pyx_v_i); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 881, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_16 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 881, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_spacing, __pyx_t_16) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;

        /* "pyquant/cpeaks.pyx":882
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)             # <<<<<<<<<<<<<<
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:
 *                     contaminant_int = contaminant_bounds.get('int', 0.)
 */
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_quant_method, __pyx_v_quant_method) < 0) __PYX_ERR(0, 880, __pyx_L1_error)
        if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_centroid, __pyx_v_centroid) < 0) __PYX_ERR(0, 880, __pyx_L1_error)

        /* "pyquant/cpeaks.pyx":880
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 *                 contaminant_bounds = findMicro(xdata, ydata, closest_contaminant_index, ppm=precursor_tolerance,             # <<<<<<<<<<<<<<
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)
 */
        __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 880, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF_SET(__pyx_v_contaminant_bounds, __pyx_t_16);
        __pyx_t_16 = 0;

        /* "pyquant/cpeaks.pyx":883
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:             # <<<<<<<<<<<<<<
 *                     contaminant_int = contaminant_bounds.get('int', 0.)
 * 
 */
        __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_contaminant_bounds, __pyx_n_s_get); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 883, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 883, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = PyObject_RichCompare(__pyx_t_9, __pyx_v_contaminant_int, Py_GT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 883, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 883, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        if (__pyx_t_12) {

          /* "pyquant/cpeaks.pyx":884
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:
 *                     contaminant_int = contaminant_bounds.get('int', 0.)             # <<<<<<<<<<<<<<
 * 
 *         # set the tolerance for isotopes
 */
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_contaminant_bounds, __pyx_n_s_get); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 884, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 884, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_DECREF_SET(__pyx_v_contaminant_int, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "pyquant/cpeaks.pyx":883
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:             # <<<<<<<<<<<<<<
 *                     contaminant_int = contaminant_bounds.get('int', 0.)
 * 
 */
        }

        /* "pyquant/cpeaks.pyx":877
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 *         if contaminant_search:
 *             for i in xrange(2, 4):             # <<<<<<<<<<<<<<
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 */
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":876
 * 
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 *         if contaminant_search:             # <<<<<<<<<<<<<<
 *             for i in xrange(2, 4):
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 */
    }

    /* "pyquant/cpeaks.pyx":887
 * 
 *         # set the tolerance for isotopes
 *         tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0             # <<<<<<<<<<<<<<
 * 
 *         while pos < df_len:
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_isotope_ppms, __pyx_n_s_get); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 887, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_16 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_16)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_16);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_8 = 1;
      }
    }
    __pyx_t_2 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 887, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_16) {
      __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_16); __pyx_t_16 = NULL;
    }
    __Pyx_INCREF(__pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_v_isotope_index);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, __pyx_v_isotope_index);
    __Pyx_INCREF(__pyx_v_isotope_ppm);
    __Pyx_GIVEREF(__pyx_v_isotope_ppm);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_v_isotope_ppm);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyFloat_DivideObjC(__pyx_t_1, __pyx_float_1000000_0, 1000000.0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 887, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_t_9); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 887, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_tolerance = __pyx_t_11;

    /* "pyquant/cpeaks.pyx":889
 *         tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 * 
 *         while pos < df_len:             # <<<<<<<<<<<<<<
 *             # search for the ppm error until it rises again, we select the minima and if this minima is
 *             # outside our ppm error, we stop the expansion of our isotopic cluster
 */
    while (1) {
      __pyx_t_9 = __Pyx_PyInt_From_Py_intptr_t(__pyx_v_df_len); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 889, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_pos, __pyx_t_9, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 889, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!__pyx_t_12) break;

      /* "pyquant/cpeaks.pyx":892
 *             # search for the ppm error until it rises again, we select the minima and if this minima is
 *             # outside our ppm error, we stop the expansion of our isotopic cluster
 *             current_loc = non_empty[pos]             # <<<<<<<<<<<<<<
 *             if max_mz is not None and current_loc >= max_mz:
 *                 if not valid_locations:
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_non_empty), __pyx_v_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 892, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_current_loc, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pyquant/cpeaks.pyx":893
 *             # outside our ppm error, we stop the expansion of our isotopic cluster
 *             current_loc = non_empty[pos]
 *             if max_mz is not None and current_loc >= max_mz:             # <<<<<<<<<<<<<<
 *                 if not valid_locations:
 *                     break
 */
      __pyx_t_5 = (__pyx_v_max_mz != Py_None);
      __pyx_t_7 = (__pyx_t_5 != 0);
      if (__pyx_t_7) {
      } else {
        __pyx_t_12 = __pyx_t_7;
        goto __pyx_L36_bool_binop_done;
      }
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_current_loc, __pyx_v_max_mz, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 893, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __pyx_t_7;
      __pyx_L36_bool_binop_done:;
      if (__pyx_t_12) {

        /* "pyquant/cpeaks.pyx":894
 *             current_loc = non_empty[pos]
 *             if max_mz is not None and current_loc >= max_mz:
 *                 if not valid_locations:             # <<<<<<<<<<<<<<
 *                     break
 *                 displacement = last_displacement+tolerance if last_displacement is not None else tolerance*2
 */
        __pyx_t_12 = (__pyx_v_valid_locations != Py_None) && (PyList_GET_SIZE(__pyx_v_valid_locations) != 0);
        __pyx_t_7 = ((!__pyx_t_12) != 0);
        if (__pyx_t_7) {

          /* "pyquant/cpeaks.pyx":895
 *             if max_mz is not None and current_loc >= max_mz:
 *                 if not valid_locations:
 *                     break             # <<<<<<<<<<<<<<
 *                 displacement = last_displacement+tolerance if last_displacement is not None else tolerance*2
 *             else:
 */
          goto __pyx_L34_break;

          /* "pyquant/cpeaks.pyx":894
 *             current_loc = non_empty[pos]
 *             if max_mz is not None and current_loc >= max_mz:
 *                 if not valid_locations:             # <<<<<<<<<<<<<<
 *                     break
 *                 displacement = last_displacement+tolerance if last_displacement is not None else tolerance*2
 */
        }

        /* "pyquant/cpeaks.pyx":896
 *                 if not valid_locations:
 *                     break
 *                 displacement = last_displacement+tolerance if last_displacement is not None else tolerance*2             # <<<<<<<<<<<<<<
 *             else:
 *                 displacement = get_ppm(start+offset, current_loc)
 */
        __pyx_t_7 = (__pyx_v_last_displacement != Py_None);
        if ((__pyx_t_7 != 0)) {
          __pyx_t_9 = PyFloat_FromDouble(__pyx_v_tolerance); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 896, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_2 = PyNumber_Add(__pyx_v_last_displacement, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_1 = __pyx_t_2;
          __pyx_t_2 = 0;
        } else {
          __pyx_t_2 = PyFloat_FromDouble((__pyx_v_tolerance * 2.0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = __pyx_t_2;
          __pyx_t_2 = 0;
        }
        __Pyx_XDECREF_SET(__pyx_v_displacement, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "pyquant/cpeaks.pyx":893
 *             # outside our ppm error, we stop the expansion of our isotopic cluster
 *             current_loc = non_empty[pos]
 *             if max_mz is not None and current_loc >= max_mz:             # <<<<<<<<<<<<<<
 *                 if not valid_locations:
 *                     break
 */
        goto __pyx_L35;
      }

      /* "pyquant/cpeaks.pyx":898
 *                 displacement = last_displacement+tolerance if last_displacement is not None else tolerance*2
 *             else:
 *                 displacement = get_ppm(start+offset, current_loc)             # <<<<<<<<<<<<<<
 *             # if debug:
 *             #     print pos, start, current_loc, displacement, last_displacement, displacement > last_displacement, last_displacement < tolerance, isotope_index, offset
 */
      /*else*/ {
        __pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_v_offset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 898, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 898, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_v_current_loc); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 898, __pyx_L1_error)
        __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_11, __pyx_t_4, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 898, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_XDECREF_SET(__pyx_v_displacement, __pyx_t_1);
        __pyx_t_1 = 0;
      }
      __pyx_L35:;

      /* "pyquant/cpeaks.pyx":902
 *             #     print pos, start, current_loc, displacement, last_displacement, displacement > last_displacement, last_displacement < tolerance, isotope_index, offset
 *             # because the peak location may be between two readings, we use a very tolerance search here and enforce the ppm at the peak fitting stage.
 *             if displacement < tolerance*5:             # <<<<<<<<<<<<<<
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:
 */
      __pyx_t_1 = PyFloat_FromDouble((__pyx_v_tolerance * 5.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 902, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_displacement, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 902, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 902, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_7) {

        /* "pyquant/cpeaks.pyx":903
 *             # because the peak location may be between two readings, we use a very tolerance search here and enforce the ppm at the peak fitting stage.
 *             if displacement < tolerance*5:
 *                 valid_locations.append((displacement, current_loc, pos))             # <<<<<<<<<<<<<<
 *             if last_displacement is not None:
 *                 if valid_locations and displacement > last_displacement:
 */
        __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_displacement);
        __Pyx_GIVEREF(__pyx_v_displacement);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_displacement);
        __Pyx_INCREF(__pyx_v_current_loc);
        __Pyx_GIVEREF(__pyx_v_current_loc);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_current_loc);
        __Pyx_INCREF(__pyx_v_pos);
        __Pyx_GIVEREF(__pyx_v_pos);
        PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_pos);
        __pyx_t_17 = __Pyx_PyList_Append(__pyx_v_valid_locations, __pyx_t_2); if (unlikely(__pyx_t_17 == -1)) __PYX_ERR(0, 903, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyquant/cpeaks.pyx":902
 *             #     print pos, start, current_loc, displacement, last_displacement, displacement > last_displacement, last_displacement < tolerance, isotope_index, offset
 *             # because the peak location may be between two readings, we use a very tolerance search here and enforce the ppm at the peak fitting stage.
 *             if displacement < tolerance*5:             # <<<<<<<<<<<<<<
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:
 */
      }

      /* "pyquant/cpeaks.pyx":904
 *             if displacement < tolerance*5:
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:             # <<<<<<<<<<<<<<
 *                 if valid_locations and displacement > last_displacement:
 *                     # pick the peak closest to our error tolerance
 */
      __pyx_t_7 = (__pyx_v_last_displacement != Py_None);
      __pyx_t_12 = (__pyx_t_7 != 0);
      if (__pyx_t_12) {

        /* "pyquant/cpeaks.pyx":905
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:
 *                 if valid_locations and displacement > last_displacement:             # <<<<<<<<<<<<<<
 *                     # pick the peak closest to our error tolerance
 *                     valid_locations2[isotope_index] = valid_locations
 */
        __pyx_t_7 = (__pyx_v_valid_locations != Py_None) && (PyList_GET_SIZE(__pyx_v_valid_locations) != 0);
        if (__pyx_t_7) {
        } else {
          __pyx_t_12 = __pyx_t_7;
          goto __pyx_L42_bool_binop_done;
        }
        __pyx_t_2 = PyObject_RichCompare(__pyx_v_displacement, __pyx_v_last_displacement, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 905, __pyx_L1_error)
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 905, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __pyx_t_7;
        __pyx_L42_bool_binop_done:;
        if (__pyx_t_12) {

          /* "pyquant/cpeaks.pyx":907
 *                 if valid_locations and displacement > last_displacement:
 *                     # pick the peak closest to our error tolerance
 *                     valid_locations2[isotope_index] = valid_locations             # <<<<<<<<<<<<<<
 *                     isotope_index += 1
 *                     tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 */
          if (unlikely(PyObject_SetItem(__pyx_v_valid_locations2, __pyx_v_isotope_index, __pyx_v_valid_locations) < 0)) __PYX_ERR(0, 907, __pyx_L1_error)

          /* "pyquant/cpeaks.pyx":908
 *                     # pick the peak closest to our error tolerance
 *                     valid_locations2[isotope_index] = valid_locations
 *                     isotope_index += 1             # <<<<<<<<<<<<<<
 *                     tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *                     offset = spacing*isotope_index
 */
          __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_isotope_index, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 908, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":909
 *                     valid_locations2[isotope_index] = valid_locations
 *                     isotope_index += 1
 *                     tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0             # <<<<<<<<<<<<<<
 *                     offset = spacing*isotope_index
 *                     displacement = get_ppm(start+offset, current_loc)
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_isotope_ppms, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = NULL;
          __pyx_t_8 = 0;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
              __pyx_t_8 = 1;
            }
          }
          __pyx_t_16 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 909, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_16);
          if (__pyx_t_9) {
            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_9); __pyx_t_9 = NULL;
          }
          __Pyx_INCREF(__pyx_v_isotope_index);
          __Pyx_GIVEREF(__pyx_v_isotope_index);
          PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_8, __pyx_v_isotope_index);
          __Pyx_INCREF(__pyx_v_isotope_ppm);
          __Pyx_GIVEREF(__pyx_v_isotope_ppm);
          PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_8, __pyx_v_isotope_ppm);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 909, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyFloat_DivideObjC(__pyx_t_2, __pyx_float_1000000_0, 1000000.0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_v_tolerance = __pyx_t_4;

          /* "pyquant/cpeaks.pyx":910
 *                     isotope_index += 1
 *                     tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *                     offset = spacing*isotope_index             # <<<<<<<<<<<<<<
 *                     displacement = get_ppm(start+offset, current_loc)
 *                     valid_locations = []
 */
          __pyx_t_1 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_v_isotope_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 910, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF_SET(__pyx_v_offset, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":911
 *                     tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *                     offset = spacing*isotope_index
 *                     displacement = get_ppm(start+offset, current_loc)             # <<<<<<<<<<<<<<
 *                     valid_locations = []
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):
 */
          __pyx_t_2 = PyNumber_Add(__pyx_v_start, __pyx_v_offset); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 911, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_4 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 911, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_11 = __pyx_PyFloat_AsFloat(__pyx_v_current_loc); if (unlikely((__pyx_t_11 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 911, __pyx_L1_error)
          __pyx_t_2 = PyFloat_FromDouble(__pyx_f_7pyquant_6cpeaks_get_ppm(__pyx_t_4, __pyx_t_11, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 911, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF_SET(__pyx_v_displacement, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":912
 *                     offset = spacing*isotope_index
 *                     displacement = get_ppm(start+offset, current_loc)
 *                     valid_locations = []             # <<<<<<<<<<<<<<
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):
 *                         break
 */
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF_SET(__pyx_v_valid_locations, ((PyObject*)__pyx_t_2));
          __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":913
 *                     displacement = get_ppm(start+offset, current_loc)
 *                     valid_locations = []
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):             # <<<<<<<<<<<<<<
 *                         break
 *                 elif displacement > last_displacement and not valid_locations:
 */
          __pyx_t_2 = PyObject_RichCompare(__pyx_v_isotopologue_limit, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
          __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 913, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (__pyx_t_7) {
          } else {
            __pyx_t_12 = __pyx_t_7;
            goto __pyx_L45_bool_binop_done;
          }
          __pyx_t_8 = PyObject_Length(__pyx_v_valid_locations2); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 913, __pyx_L1_error)
          __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_v_isotopologue_limit, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 913, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_12 = __pyx_t_7;
          __pyx_L45_bool_binop_done:;
          if (__pyx_t_12) {

            /* "pyquant/cpeaks.pyx":914
 *                     valid_locations = []
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):
 *                         break             # <<<<<<<<<<<<<<
 *                 elif displacement > last_displacement and not valid_locations:
 *                     break
 */
            goto __pyx_L34_break;

            /* "pyquant/cpeaks.pyx":913
 *                     displacement = get_ppm(start+offset, current_loc)
 *                     valid_locations = []
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):             # <<<<<<<<<<<<<<
 *                         break
 *                 elif displacement > last_displacement and not valid_locations:
 */
          }

          /* "pyquant/cpeaks.pyx":905
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:
 *                 if valid_locations and displacement > last_displacement:             # <<<<<<<<<<<<<<
 *                     # pick the peak closest to our error tolerance
 *                     valid_locations2[isotope_index] = valid_locations
 */
          goto __pyx_L41;
        }

        /* "pyquant/cpeaks.pyx":915
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):
 *                         break
 *                 elif displacement > last_displacement and not valid_locations:             # <<<<<<<<<<<<<<
 *                     break
 *             last_displacement = displacement
 */
        __pyx_t_1 = PyObject_RichCompare(__pyx_v_displacement, __pyx_v_last_displacement, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 915, __pyx_L1_error)
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 915, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_7) {
        } else {
          __pyx_t_12 = __pyx_t_7;
          goto __pyx_L47_bool_binop_done;
        }
        __pyx_t_7 = (__pyx_v_valid_locations != Py_None) && (PyList_GET_SIZE(__pyx_v_valid_locations) != 0);
        __pyx_t_5 = ((!__pyx_t_7) != 0);
        __pyx_t_12 = __pyx_t_5;
        __pyx_L47_bool_binop_done:;
        if (__pyx_t_12) {

          /* "pyquant/cpeaks.pyx":916
 *                         break
 *                 elif displacement > last_displacement and not valid_locations:
 *                     break             # <<<<<<<<<<<<<<
 *             last_displacement = displacement
 *             pos += 1
 */
          goto __pyx_L34_break;

          /* "pyquant/cpeaks.pyx":915
 *                     if isotopologue_limit != -1 and (len(valid_locations2) >= isotopologue_limit):
 *                         break
 *                 elif displacement > last_displacement and not valid_locations:             # <<<<<<<<<<<<<<
 *                     break
 *             last_displacement = displacement
 */
        }
        __pyx_L41:;

        /* "pyquant/cpeaks.pyx":904
 *             if displacement < tolerance*5:
 *                 valid_locations.append((displacement, current_loc, pos))
 *             if last_displacement is not None:             # <<<<<<<<<<<<<<
 *                 if valid_locations and displacement > last_displacement:
 *                     # pick the peak closest to our error tolerance
 */
      }

      /* "pyquant/cpeaks.pyx":917
 *                 elif displacement > last_displacement and not valid_locations:
 *                     break
 *             last_displacement = displacement             # <<<<<<<<<<<<<<
 *             pos += 1
 * 
 */
      __Pyx_INCREF(__pyx_v_displacement);
      __Pyx_DECREF_SET(__pyx_v_last_displacement, __pyx_v_displacement);

      /* "pyquant/cpeaks.pyx":918
 *                     break
 *             last_displacement = displacement
 *             pos += 1             # <<<<<<<<<<<<<<
 * 
 *     #combine any overlapping micro envelopes
 */
      __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_pos, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 918, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_pos, __pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L34_break:;

    /* "pyquant/cpeaks.pyx":867
 *     contaminant_int = 0.
 * 
 *     if not reporter_mode and (isotopologue_limit == -1 or len(valid_locations2) < isotopologue_limit):             # <<<<<<<<<<<<<<
 *         isotope_index += 1
 *         pos = find_nearest_index(non_empty, start)+1
 */
  }

  /* "pyquant/cpeaks.pyx":922
 *     #combine any overlapping micro envelopes
 *     #final_micros = self.merge_list(micro_dict)
 *     valid_keys = sorted(set(valid_locations2.keys()).intersection(theo_dist.keys() if theo_dist is not None else valid_locations2.keys()))             # <<<<<<<<<<<<<<
 *     # This attempts to use a diophantine equation to match the clusters to the theoretical distribution of isotopes
 *     #valid_vals = [j[1] for i in valid_keys for j in valid_locations2[i]]
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_valid_locations2, __pyx_n_s_keys); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 922, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  if (__pyx_t_6) {
    __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    __pyx_t_16 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 922, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PySet_New(__pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 922, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_intersection); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 922, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_12 = (__pyx_v_theo_dist != Py_None);
  if ((__pyx_t_12 != 0)) {
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_theo_dist, __pyx_n_s_keys); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_14, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 922, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_14); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 922, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_9 = __pyx_t_6;
    __pyx_t_6 = 0;
  } else {
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_valid_locations2, __pyx_n_s_keys); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_14, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 922, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_14); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 922, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_9 = __pyx_t_6;
    __pyx_t_6 = 0;
  }
  __pyx_t_6 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL;
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 922, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = ((PyObject*)__pyx_t_16);
  __pyx_t_16 = 0;
  __pyx_t_17 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_17 == -1)) __PYX_ERR(0, 922, __pyx_L1_error)
  __pyx_v_valid_keys = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":928
 *     #valid_theor = valid_theor/valid_theor.max()
 *     #best_locations = sorted(looper(selected=valid_vals, df=df, theo=valid_theor), key=itemgetter(0))[0][1]
 *     best_locations = [sorted(valid_locations2[i], key=itemgetter(0))[0] for i in valid_keys]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__pyx_v_valid_keys == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 928, __pyx_L1_error)
  }
  __pyx_t_16 = __pyx_v_valid_keys; __Pyx_INCREF(__pyx_t_16); __pyx_t_8 = 0;
  for (;;) {
    if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_16)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 928, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_16, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_GetItem(__pyx_v_valid_locations2, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_6) < 0) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_14, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_v_best_locations = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":931
 * 
 * 
 *     for index, isotope_index in enumerate(valid_keys):             # <<<<<<<<<<<<<<
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:
 *             continue
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_16 = __pyx_v_valid_keys; __Pyx_INCREF(__pyx_t_16); __pyx_t_8 = 0;
  for (;;) {
    if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_16)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 931, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_16, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":932
 * 
 *     for index, isotope_index in enumerate(valid_keys):
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:             # <<<<<<<<<<<<<<
 *             continue
 *         _, _, empty_index = best_locations[index]
 */
    __pyx_t_5 = (__pyx_v_skip_isotopes != Py_None);
    __pyx_t_7 = (__pyx_t_5 != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_12 = __pyx_t_7;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_isotope_index, __pyx_v_skip_isotopes, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 932, __pyx_L1_error)
    __pyx_t_5 = (__pyx_t_7 != 0);
    __pyx_t_12 = __pyx_t_5;
    __pyx_L54_bool_binop_done:;
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":933
 *     for index, isotope_index in enumerate(valid_keys):
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:
 *             continue             # <<<<<<<<<<<<<<
 *         _, _, empty_index = best_locations[index]
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])
 */
      goto __pyx_L51_continue;

      /* "pyquant/cpeaks.pyx":932
 * 
 *     for index, isotope_index in enumerate(valid_keys):
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:             # <<<<<<<<<<<<<<
 *             continue
 *         _, _, empty_index = best_locations[index]
 */
    }

    /* "pyquant/cpeaks.pyx":934
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:
 *             continue
 *         _, _, empty_index = best_locations[index]             # <<<<<<<<<<<<<<
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])
 *         if ydata[micro_index] == 0:
 */
    __pyx_t_2 = PyObject_GetItem(__pyx_v_best_locations, __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 934, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 934, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_14);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 934, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 934, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_9 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 934, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 934, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext;
      index = 0; __pyx_t_6 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_6)) goto __pyx_L56_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 1; __pyx_t_14 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L56_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_14);
      index = 2; __pyx_t_9 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_9)) goto __pyx_L56_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_3), 3) < 0) __PYX_ERR(0, 934, __pyx_L1_error)
      __pyx_t_18 = NULL;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L57_unpacking_done;
      __pyx_L56_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_18 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 934, __pyx_L1_error)
      __pyx_L57_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v__, __pyx_t_14);
    __pyx_t_14 = 0;
    __Pyx_XDECREF_SET(__pyx_v_empty_index, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pyquant/cpeaks.pyx":935
 *             continue
 *         _, _, empty_index = best_locations[index]
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])             # <<<<<<<<<<<<<<
 *         if ydata[micro_index] == 0:
 *             micro_index += 1
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_find_nearest_index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = PyObject_GetItem(((PyObject *)__pyx_v_non_empty), __pyx_v_empty_index); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_6 = NULL;
    __pyx_t_15 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_15 = 1;
      }
    }
    __pyx_t_3 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_15, ((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_15, __pyx_t_14);
    __pyx_t_14 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_micro_index, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pyquant/cpeaks.pyx":936
 *         _, _, empty_index = best_locations[index]
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])
 *         if ydata[micro_index] == 0:             # <<<<<<<<<<<<<<
 *             micro_index += 1
 *         if ydata[micro_index] == 0:
 */
    __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_ydata), __pyx_v_micro_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 936, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 936, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 936, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":937
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])
 *         if ydata[micro_index] == 0:
 *             micro_index += 1             # <<<<<<<<<<<<<<
 *         if ydata[micro_index] == 0:
 *             micro_index -= 2
 */
      __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_micro_index, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 937, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF_SET(__pyx_v_micro_index, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pyquant/cpeaks.pyx":936
 *         _, _, empty_index = best_locations[index]
 *         micro_index = find_nearest_index(xdata, non_empty[empty_index])
 *         if ydata[micro_index] == 0:             # <<<<<<<<<<<<<<
 *             micro_index += 1
 *         if ydata[micro_index] == 0:
 */
    }

    /* "pyquant/cpeaks.pyx":938
 *         if ydata[micro_index] == 0:
 *             micro_index += 1
 *         if ydata[micro_index] == 0:             # <<<<<<<<<<<<<<
 *             micro_index -= 2
 *         # if micro_index == 0:
 */
    __pyx_t_9 = PyObject_GetItem(((PyObject *)__pyx_v_ydata), __pyx_v_micro_index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_9, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 938, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":939
 *             micro_index += 1
 *         if ydata[micro_index] == 0:
 *             micro_index -= 2             # <<<<<<<<<<<<<<
 *         # if micro_index == 0:
 *         #     pass
 */
      __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_micro_index, __pyx_int_2, 2, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 939, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_micro_index, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":938
 *         if ydata[micro_index] == 0:
 *             micro_index += 1
 *         if ydata[micro_index] == 0:             # <<<<<<<<<<<<<<
 *             micro_index -= 2
 *         # if micro_index == 0:
 */
    }

    /* "pyquant/cpeaks.pyx":942
 *         # if micro_index == 0:
 *         #     pass
 *         isotope_tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0             # <<<<<<<<<<<<<<
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_isotope_ppms, __pyx_n_s_get); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_3 = NULL;
    __pyx_t_15 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_15 = 1;
      }
    }
    __pyx_t_14 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_v_isotope_index);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_15, __pyx_v_isotope_index);
    __Pyx_INCREF(__pyx_v_isotope_ppm);
    __Pyx_GIVEREF(__pyx_v_isotope_ppm);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_15, __pyx_v_isotope_ppm);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyFloat_DivideObjC(__pyx_t_2, __pyx_float_1000000_0, 1000000.0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_isotope_tolerance, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pyquant/cpeaks.pyx":943
 *         #     pass
 *         isotope_tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,             # <<<<<<<<<<<<<<
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 *         if isotope_index == 0:
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_findMicro); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_xdata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_xdata));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_xdata));
    __Pyx_INCREF(((PyObject *)__pyx_v_ydata));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ydata));
    PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_ydata));
    __Pyx_INCREF(__pyx_v_micro_index);
    __Pyx_GIVEREF(__pyx_v_micro_index);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_micro_index);
    __pyx_t_14 = PyDict_New(); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_v_isotope_index, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_12) {
      __pyx_t_6 = PyFloat_FromDouble(__pyx_v_precursor_tolerance); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 943, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __pyx_t_6;
      __pyx_t_6 = 0;
    } else {
      __Pyx_INCREF(__pyx_v_isotope_tolerance);
      __pyx_t_3 = __pyx_v_isotope_tolerance;
    }
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_ppm, __pyx_t_3) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":944
 *         isotope_tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)             # <<<<<<<<<<<<<<
 *         if isotope_index == 0:
 *             micro_bounds['error'] = start_error
 */
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_calc_start_mz, __pyx_v_start) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_start_mz, __pyx_v_start_mz) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_isotope, __pyx_v_isotope_index) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_spacing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_spacing, __pyx_t_3) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_quant_method, __pyx_v_quant_method) < 0) __PYX_ERR(0, 943, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_centroid, __pyx_v_centroid) < 0) __PYX_ERR(0, 943, __pyx_L1_error)

    /* "pyquant/cpeaks.pyx":943
 *         #     pass
 *         isotope_tolerance = isotope_ppms.get(isotope_index, isotope_ppm)/1000000.0
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,             # <<<<<<<<<<<<<<
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 *         if isotope_index == 0:
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF_SET(__pyx_v_micro_bounds, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pyquant/cpeaks.pyx":945
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 *         if isotope_index == 0:             # <<<<<<<<<<<<<<
 *             micro_bounds['error'] = start_error
 * 
 */
    __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_isotope_index, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 945, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_12) {

      /* "pyquant/cpeaks.pyx":946
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 *         if isotope_index == 0:
 *             micro_bounds['error'] = start_error             # <<<<<<<<<<<<<<
 * 
 *         micro_dict[isotope_index] = micro_bounds
 */
      if (unlikely(PyObject_SetItem(__pyx_v_micro_bounds, __pyx_n_s_error, __pyx_v_start_error) < 0)) __PYX_ERR(0, 946, __pyx_L1_error)

      /* "pyquant/cpeaks.pyx":945
 *         micro_bounds = findMicro(xdata, ydata, micro_index, ppm=precursor_tolerance if isotope_index == 0 else isotope_tolerance,
 *                                  calc_start_mz=start, start_mz=start_mz, isotope=isotope_index, spacing=spacing, quant_method=quant_method, centroid=centroid)
 *         if isotope_index == 0:             # <<<<<<<<<<<<<<
 *             micro_bounds['error'] = start_error
 * 
 */
    }

    /* "pyquant/cpeaks.pyx":948
 *             micro_bounds['error'] = start_error
 * 
 *         micro_dict[isotope_index] = micro_bounds             # <<<<<<<<<<<<<<
 *         env_dict[isotope_index] = micro_index
 *         ppm_dict[isotope_index] = micro_bounds.get('error')
 */
    if (unlikely(PyObject_SetItem(__pyx_v_micro_dict, __pyx_v_isotope_index, __pyx_v_micro_bounds) < 0)) __PYX_ERR(0, 948, __pyx_L1_error)

    /* "pyquant/cpeaks.pyx":949
 * 
 *         micro_dict[isotope_index] = micro_bounds
 *         env_dict[isotope_index] = micro_index             # <<<<<<<<<<<<<<
 *         ppm_dict[isotope_index] = micro_bounds.get('error')
 * 
 */
    if (unlikely(PyObject_SetItem(__pyx_v_env_dict, __pyx_v_isotope_index, __pyx_v_micro_index) < 0)) __PYX_ERR(0, 949, __pyx_L1_error)

    /* "pyquant/cpeaks.pyx":950
 *         micro_dict[isotope_index] = micro_bounds
 *         env_dict[isotope_index] = micro_index
 *         ppm_dict[isotope_index] = micro_bounds.get('error')             # <<<<<<<<<<<<<<
 * 
 *     # in all cases, the envelope is going to be either monotonically decreasing, or a parabola (-x^2)
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_bounds, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_ppm_dict, __pyx_v_isotope_index, __pyx_t_14) < 0)) __PYX_ERR(0, 950, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "pyquant/cpeaks.pyx":931
 * 
 * 
 *     for index, isotope_index in enumerate(valid_keys):             # <<<<<<<<<<<<<<
 *         if skip_isotopes is not None and isotope_index in skip_isotopes:
 *             continue
 */
    __pyx_L51_continue:;
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":953
 * 
 *     # in all cases, the envelope is going to be either monotonically decreasing, or a parabola (-x^2)
 *     isotope_pattern = [(isotope_index, isotope_dict['int']) for isotope_index, isotope_dict in micro_dict.items()]             # <<<<<<<<<<<<<<
 *     # Empirically, it's been found that enforcing the theoretical distribution on a per ms1 scan basis leads to
 *     # significant increases in variance for the XIC
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 953, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_dict, __pyx_n_s_items); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 953, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_14, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_16 = __Pyx_PyObject_CallNoArg(__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 953, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  if (likely(PyList_CheckExact(__pyx_t_16)) || PyTuple_CheckExact(__pyx_t_16)) {
    __pyx_t_14 = __pyx_t_16; __Pyx_INCREF(__pyx_t_14); __pyx_t_8 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_16); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_13 = Py_TYPE(__pyx_t_14)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 953, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_14))) {
        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_14)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_16 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_8); __Pyx_INCREF(__pyx_t_16); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 953, __pyx_L1_error)
        #else
        __pyx_t_16 = PySequence_ITEM(__pyx_t_14, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        #endif
      } else {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_14)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_16 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_8); __Pyx_INCREF(__pyx_t_16); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 953, __pyx_L1_error)
        #else
        __pyx_t_16 = PySequence_ITEM(__pyx_t_14, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        #endif
      }
    } else {
      __pyx_t_16 = __pyx_t_13(__pyx_t_14);
      if (unlikely(!__pyx_t_16)) {
        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, 953, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_16);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_16))) || (PyList_CheckExact(__pyx_t_16))) {
      PyObject* sequence = __pyx_t_16;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 953, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 953, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_9 = PyObject_GetIter(__pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 953, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_18 = Py_TYPE(__pyx_t_9)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_18(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L63_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_2 = __pyx_t_18(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L63_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_9), 2) < 0) __PYX_ERR(0, 953, __pyx_L1_error)
      __pyx_t_18 = NULL;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L64_unpacking_done;
      __pyx_L63_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_18 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 953, __pyx_L1_error)
      __pyx_L64_unpacking_done:;
    }
    __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_isotope_dict, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_16 = PyObject_GetItem(__pyx_v_isotope_dict, __pyx_n_s_int); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_v_isotope_index);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_16);
    __pyx_t_16 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_v_isotope_pattern = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":991
 *         #             micro_dict.pop(isotope_index)
 *         #             ppm_dict.pop(isotope_index)
 *     if contaminant_int > 1:             # <<<<<<<<<<<<<<
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_contaminant_int, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 991, __pyx_L1_error)
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_12) {

    /* "pyquant/cpeaks.pyx":992
 *         #             ppm_dict.pop(isotope_index)
 *     if contaminant_int > 1:
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):             # <<<<<<<<<<<<<<
 *             if contaminant_int > isotope_intensity:
 *                 if debug:
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_1 = __pyx_int_0;
    __pyx_t_14 = __pyx_v_isotope_pattern; __Pyx_INCREF(__pyx_t_14); __pyx_t_8 = 0;
    for (;;) {
      if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_14)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 992, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_14, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 992, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 992, __pyx_L1_error)
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_16 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_16 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_16);
        __Pyx_INCREF(__pyx_t_3);
        #else
        __pyx_t_16 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 992, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 992, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 992, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_18 = Py_TYPE(__pyx_t_9)->tp_iternext;
        index = 0; __pyx_t_16 = __pyx_t_18(__pyx_t_9); if (unlikely(!__pyx_t_16)) goto __pyx_L68_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_16);
        index = 1; __pyx_t_3 = __pyx_t_18(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L68_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_9), 2) < 0) __PYX_ERR(0, 992, __pyx_L1_error)
        __pyx_t_18 = NULL;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L69_unpacking_done;
        __pyx_L68_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_18 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 992, __pyx_L1_error)
        __pyx_L69_unpacking_done:;
      }
      __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_16);
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_isotope_intensity, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 992, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1);
      __pyx_t_1 = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "pyquant/cpeaks.pyx":993
 *     if contaminant_int > 1:
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:             # <<<<<<<<<<<<<<
 *                 if debug:
 *                     print('contaminant loss', label)
 */
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_contaminant_int, __pyx_v_isotope_intensity, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 993, __pyx_L1_error)
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 993, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_12) {

        /* "pyquant/cpeaks.pyx":994
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:
 *                 if debug:             # <<<<<<<<<<<<<<
 *                     print('contaminant loss', label)
 *                 env_dict.pop(isotope_index)
 */
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 994, __pyx_L1_error)
        if (__pyx_t_12) {

          /* "pyquant/cpeaks.pyx":995
 *             if contaminant_int > isotope_intensity:
 *                 if debug:
 *                     print('contaminant loss', label)             # <<<<<<<<<<<<<<
 *                 env_dict.pop(isotope_index)
 *                 micro_dict.pop(isotope_index)
 */
          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 995, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_kp_s_contaminant_loss);
          __Pyx_GIVEREF(__pyx_kp_s_contaminant_loss);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_s_contaminant_loss);
          __Pyx_INCREF(__pyx_v_label);
          __Pyx_GIVEREF(__pyx_v_label);
          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_label);
          if (__Pyx_PrintOne(0, __pyx_t_2) < 0) __PYX_ERR(0, 995, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pyquant/cpeaks.pyx":994
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:
 *                 if debug:             # <<<<<<<<<<<<<<
 *                     print('contaminant loss', label)
 *                 env_dict.pop(isotope_index)
 */
        }

        /* "pyquant/cpeaks.pyx":996
 *                 if debug:
 *                     print('contaminant loss', label)
 *                 env_dict.pop(isotope_index)             # <<<<<<<<<<<<<<
 *                 micro_dict.pop(isotope_index)
 *                 ppm_dict.pop(isotope_index)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_env_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 996, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_16 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_16)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_16);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_16) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_isotope_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 996, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 996, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_16); __pyx_t_16 = NULL;
          __Pyx_INCREF(__pyx_v_isotope_index);
          __Pyx_GIVEREF(__pyx_v_isotope_index);
          PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_isotope_index);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 996, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyquant/cpeaks.pyx":997
 *                     print('contaminant loss', label)
 *                 env_dict.pop(isotope_index)
 *                 micro_dict.pop(isotope_index)             # <<<<<<<<<<<<<<
 *                 ppm_dict.pop(isotope_index)
 *     # rebuild the pattern after contaminants are removed
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 997, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_9) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_isotope_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 997, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 997, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_9); __pyx_t_9 = NULL;
          __Pyx_INCREF(__pyx_v_isotope_index);
          __Pyx_GIVEREF(__pyx_v_isotope_index);
          PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_v_isotope_index);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 997, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyquant/cpeaks.pyx":998
 *                 env_dict.pop(isotope_index)
 *                 micro_dict.pop(isotope_index)
 *                 ppm_dict.pop(isotope_index)             # <<<<<<<<<<<<<<
 *     # rebuild the pattern after contaminants are removed
 *     isotope_pattern = [(isotope_index, isotope_dict['int']) for isotope_index, isotope_dict in micro_dict.items()]
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ppm_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 998, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_16 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_16)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_16);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_16) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_isotope_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 998, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 998, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_16); __pyx_t_16 = NULL;
          __Pyx_INCREF(__pyx_v_isotope_index);
          __Pyx_GIVEREF(__pyx_v_isotope_index);
          PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_isotope_index);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 998, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyquant/cpeaks.pyx":993
 *     if contaminant_int > 1:
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:             # <<<<<<<<<<<<<<
 *                 if debug:
 *                     print('contaminant loss', label)
 */
      }

      /* "pyquant/cpeaks.pyx":992
 *         #             ppm_dict.pop(isotope_index)
 *     if contaminant_int > 1:
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):             # <<<<<<<<<<<<<<
 *             if contaminant_int > isotope_intensity:
 *                 if debug:
 */
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pyquant/cpeaks.pyx":991
 *         #             micro_dict.pop(isotope_index)
 *         #             ppm_dict.pop(isotope_index)
 *     if contaminant_int > 1:             # <<<<<<<<<<<<<<
 *         for i,(isotope_index, isotope_intensity) in enumerate(isotope_pattern):
 *             if contaminant_int > isotope_intensity:
 */
  }

  /* "pyquant/cpeaks.pyx":1000
 *                 ppm_dict.pop(isotope_index)
 *     # rebuild the pattern after contaminants are removed
 *     isotope_pattern = [(isotope_index, isotope_dict['int']) for isotope_index, isotope_dict in micro_dict.items()]             # <<<<<<<<<<<<<<
 *     if theo_dist is None:
 *         # are we monotonically decreasing?
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_dict, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(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_14 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_14 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1000, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_14)) || PyTuple_CheckExact(__pyx_t_14)) {
    __pyx_t_2 = __pyx_t_14; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1000, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_14); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error)
        #else
        __pyx_t_14 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1000, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
      } else {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_14); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error)
        #else
        __pyx_t_14 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1000, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
      }
    } else {
      __pyx_t_14 = __pyx_t_13(__pyx_t_2);
      if (unlikely(!__pyx_t_14)) {
        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, 1000, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_14);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) {
      PyObject* sequence = __pyx_t_14;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1000, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_18 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_18(__pyx_t_16); if (unlikely(!__pyx_t_3)) goto __pyx_L74_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_9 = __pyx_t_18(__pyx_t_16); if (unlikely(!__pyx_t_9)) goto __pyx_L74_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_16), 2) < 0) __PYX_ERR(0, 1000, __pyx_L1_error)
      __pyx_t_18 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L75_unpacking_done;
      __pyx_L74_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_18 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1000, __pyx_L1_error)
      __pyx_L75_unpacking_done:;
    }
    __Pyx_DECREF_SET(__pyx_v_isotope_index, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_isotope_dict, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_14 = PyObject_GetItem(__pyx_v_isotope_dict, __pyx_n_s_int); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_v_isotope_index);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_isotope_index);
    __Pyx_GIVEREF(__pyx_t_14);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_14);
    __pyx_t_14 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_isotope_pattern, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":1001
 *     # rebuild the pattern after contaminants are removed
 *     isotope_pattern = [(isotope_index, isotope_dict['int']) for isotope_index, isotope_dict in micro_dict.items()]
 *     if theo_dist is None:             # <<<<<<<<<<<<<<
 *         # are we monotonically decreasing?
 *         remove = False
 */
  __pyx_t_12 = (__pyx_v_theo_dist == Py_None);
  __pyx_t_5 = (__pyx_t_12 != 0);
  if (__pyx_t_5) {

    /* "pyquant/cpeaks.pyx":1003
 *     if theo_dist is None:
 *         # are we monotonically decreasing?
 *         remove = False             # <<<<<<<<<<<<<<
 *         if len(isotope_pattern) > 2:
 *             # check if the 2nd isotope is smaller than the first. This is a classical case looking like:
 */
    __pyx_v_remove = 0;

    /* "pyquant/cpeaks.pyx":1004
 *         # are we monotonically decreasing?
 *         remove = False
 *         if len(isotope_pattern) > 2:             # <<<<<<<<<<<<<<
 *             # check if the 2nd isotope is smaller than the first. This is a classical case looking like:
 *             #
 */
    __pyx_t_8 = PyList_GET_SIZE(__pyx_v_isotope_pattern); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 1004, __pyx_L1_error)
    __pyx_t_5 = ((__pyx_t_8 > 2) != 0);
    if (__pyx_t_5) {

      /* "pyquant/cpeaks.pyx":1012
 *             #  |  |  |  |
 * 
 *             if isotope_pattern[1][1] < isotope_pattern[0][1]:             # <<<<<<<<<<<<<<
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 */
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_isotope_pattern, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_isotope_pattern, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_9, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_5) {

        /* "pyquant/cpeaks.pyx":1014
 *             if isotope_pattern[1][1] < isotope_pattern[0][1]:
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):             # <<<<<<<<<<<<<<
 *                     if j[1]*0.9 > i[1]:
 *                         # the pattern broke, remove isotopes beyond this point
 */
        __pyx_t_1 = __Pyx_PyList_GetSlice(__pyx_v_isotope_pattern, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_v_isotope_pattern);
        __Pyx_GIVEREF(__pyx_v_isotope_pattern);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_isotope_pattern);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
          __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_8 = 0;
          __pyx_t_13 = NULL;
        } else {
          __pyx_t_8 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1014, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_13 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1014, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        for (;;) {
          if (likely(!__pyx_t_13)) {
            if (likely(PyList_CheckExact(__pyx_t_9))) {
              if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1014, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1014, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            } else {
              if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1014, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1014, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            }
          } else {
            __pyx_t_1 = __pyx_t_13(__pyx_t_9);
            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, 1014, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_1);
          }
          if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
            PyObject* sequence = __pyx_t_1;
            #if CYTHON_COMPILING_IN_CPYTHON
            Py_ssize_t size = Py_SIZE(sequence);
            #else
            Py_ssize_t size = PySequence_Size(sequence);
            #endif
            if (unlikely(size != 2)) {
              if (size > 2) __Pyx_RaiseTooManyValuesError(2);
              else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
              __PYX_ERR(0, 1014, __pyx_L1_error)
            }
            #if CYTHON_COMPILING_IN_CPYTHON
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_14);
            #else
            __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1014, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1014, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_14);
            #endif
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1014, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext;
            index = 0; __pyx_t_2 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L81_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_2);
            index = 1; __pyx_t_14 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L81_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_14);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1014, __pyx_L1_error)
            __pyx_t_18 = NULL;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            goto __pyx_L82_unpacking_done;
            __pyx_L81_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_18 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 1014, __pyx_L1_error)
            __pyx_L82_unpacking_done:;
          }
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
          __pyx_t_2 = 0;
          __Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_14);
          __pyx_t_14 = 0;

          /* "pyquant/cpeaks.pyx":1015
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if j[1]*0.9 > i[1]:             # <<<<<<<<<<<<<<
 *                         # the pattern broke, remove isotopes beyond this point
 *                         remove = True
 */
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_j, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_14 = PyNumber_Multiply(__pyx_t_1, __pyx_float_0_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_i, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = PyObject_RichCompare(__pyx_t_14, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (__pyx_t_5) {

            /* "pyquant/cpeaks.pyx":1017
 *                     if j[1]*0.9 > i[1]:
 *                         # the pattern broke, remove isotopes beyond this point
 *                         remove = True             # <<<<<<<<<<<<<<
 *                     if remove:
 *                         if debug:
 */
            __pyx_v_remove = 1;

            /* "pyquant/cpeaks.pyx":1015
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if j[1]*0.9 > i[1]:             # <<<<<<<<<<<<<<
 *                         # the pattern broke, remove isotopes beyond this point
 *                         remove = True
 */
          }

          /* "pyquant/cpeaks.pyx":1018
 *                         # the pattern broke, remove isotopes beyond this point
 *                         remove = True
 *                     if remove:             # <<<<<<<<<<<<<<
 *                         if debug:
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 */
          __pyx_t_5 = (__pyx_v_remove != 0);
          if (__pyx_t_5) {

            /* "pyquant/cpeaks.pyx":1019
 *                         remove = True
 *                     if remove:
 *                         if debug:             # <<<<<<<<<<<<<<
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 */
            __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1019, __pyx_L1_error)
            if (__pyx_t_5) {

              /* "pyquant/cpeaks.pyx":1020
 *                     if remove:
 *                         if debug:
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)             # <<<<<<<<<<<<<<
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])
 */
              __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1020, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_INCREF(__pyx_kp_s_pattern2_1_loss);
              __Pyx_GIVEREF(__pyx_kp_s_pattern2_1_loss);
              PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s_pattern2_1_loss);
              __Pyx_INCREF(__pyx_v_label);
              __Pyx_GIVEREF(__pyx_v_label);
              PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_label);
              __Pyx_GIVEREF(__pyx_t_2);
              PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2);
              __Pyx_INCREF(__pyx_v_isotope_pattern);
              __Pyx_GIVEREF(__pyx_v_isotope_pattern);
              PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_isotope_pattern);
              __pyx_t_2 = 0;
              if (__Pyx_PrintOne(0, __pyx_t_1) < 0) __PYX_ERR(0, 1020, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

              /* "pyquant/cpeaks.pyx":1019
 *                         remove = True
 *                     if remove:
 *                         if debug:             # <<<<<<<<<<<<<<
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 */
            }

            /* "pyquant/cpeaks.pyx":1021
 *                         if debug:
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])             # <<<<<<<<<<<<<<
 *                         micro_dict.pop(j[0])
 *                         ppm_dict.pop(j[0])
 */
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_env_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1021, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1021, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_14);
            __pyx_t_3 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(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_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
              __Pyx_GOTREF(__pyx_t_1);
            } else {
              __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1021, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_3); __pyx_t_3 = NULL;
              __Pyx_GIVEREF(__pyx_t_14);
              PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_t_14);
              __pyx_t_14 = 0;
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "pyquant/cpeaks.pyx":1022
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])             # <<<<<<<<<<<<<<
 *                         ppm_dict.pop(j[0])
 * 
 */
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1022, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1022, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_16);
            __pyx_t_14 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
              __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_2);
              if (likely(__pyx_t_14)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
                __Pyx_INCREF(__pyx_t_14);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_2, function);
              }
            }
            if (!__pyx_t_14) {
              __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1022, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_1);
            } else {
              __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1022, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_14); __pyx_t_14 = NULL;
              __Pyx_GIVEREF(__pyx_t_16);
              PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_16);
              __pyx_t_16 = 0;
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1022, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "pyquant/cpeaks.pyx":1023
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])
 *                         ppm_dict.pop(j[0])             # <<<<<<<<<<<<<<
 * 
 *             # check if the 2nd isotope is larger than the first. This is a case looking like:
 */
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_ppm_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1023, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1023, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_16 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
              __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_2);
              if (likely(__pyx_t_16)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
                __Pyx_INCREF(__pyx_t_16);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_2, function);
              }
            }
            if (!__pyx_t_16) {
              __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1023, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_1);
            } else {
              __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1023, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_16); __pyx_t_16 = NULL;
              __Pyx_GIVEREF(__pyx_t_3);
              PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_3);
              __pyx_t_3 = 0;
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1023, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "pyquant/cpeaks.pyx":1018
 *                         # the pattern broke, remove isotopes beyond this point
 *                         remove = True
 *                     if remove:             # <<<<<<<<<<<<<<
 *                         if debug:
 *                             print('pattern2.1 loss', label, j[0], isotope_pattern)
 */
          }

          /* "pyquant/cpeaks.pyx":1014
 *             if isotope_pattern[1][1] < isotope_pattern[0][1]:
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):             # <<<<<<<<<<<<<<
 *                     if j[1]*0.9 > i[1]:
 *                         # the pattern broke, remove isotopes beyond this point
 */
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pyquant/cpeaks.pyx":1012
 *             #  |  |  |  |
 * 
 *             if isotope_pattern[1][1] < isotope_pattern[0][1]:             # <<<<<<<<<<<<<<
 *                 # we are, check this trend holds and remove isotopes it fails for
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 */
        goto __pyx_L78;
      }

      /* "pyquant/cpeaks.pyx":1032
 *             #  |  |  |  |
 * 
 *             elif isotope_pattern[1][1] > isotope_pattern[0][1]:             # <<<<<<<<<<<<<<
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 */
      __pyx_t_9 = __Pyx_GetItemInt_List(__pyx_v_isotope_pattern, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_9, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_GetItemInt_List(__pyx_v_isotope_pattern, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_9, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1032, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_5) {

        /* "pyquant/cpeaks.pyx":1033
 * 
 *             elif isotope_pattern[1][1] > isotope_pattern[0][1]:
 *                 shift = False             # <<<<<<<<<<<<<<
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if shift and j[1]*0.9 > i[1]:
 */
        __pyx_v_shift = 0;

        /* "pyquant/cpeaks.pyx":1034
 *             elif isotope_pattern[1][1] > isotope_pattern[0][1]:
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):             # <<<<<<<<<<<<<<
 *                     if shift and j[1]*0.9 > i[1]:
 *                         remove = True
 */
        __pyx_t_9 = __Pyx_PyList_GetSlice(__pyx_v_isotope_pattern, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1034, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1034, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_isotope_pattern);
        __Pyx_GIVEREF(__pyx_v_isotope_pattern);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_isotope_pattern);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1034, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
          __pyx_t_2 = __pyx_t_9; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0;
          __pyx_t_13 = NULL;
        } else {
          __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1034, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1034, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        for (;;) {
          if (likely(!__pyx_t_13)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_9 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_9); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1034, __pyx_L1_error)
              #else
              __pyx_t_9 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1034, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              #endif
            } else {
              if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_9); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1034, __pyx_L1_error)
              #else
              __pyx_t_9 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1034, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              #endif
            }
          } else {
            __pyx_t_9 = __pyx_t_13(__pyx_t_2);
            if (unlikely(!__pyx_t_9)) {
              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, 1034, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_9);
          }
          if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
            PyObject* sequence = __pyx_t_9;
            #if CYTHON_COMPILING_IN_CPYTHON
            Py_ssize_t size = Py_SIZE(sequence);
            #else
            Py_ssize_t size = PySequence_Size(sequence);
            #endif
            if (unlikely(size != 2)) {
              if (size > 2) __Pyx_RaiseTooManyValuesError(2);
              else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
              __PYX_ERR(0, 1034, __pyx_L1_error)
            }
            #if CYTHON_COMPILING_IN_CPYTHON
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_14);
            #else
            __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1034, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1034, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_14);
            #endif
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_3 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1034, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext;
            index = 0; __pyx_t_1 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L88_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_1);
            index = 1; __pyx_t_14 = __pyx_t_18(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L88_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_14);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1034, __pyx_L1_error)
            __pyx_t_18 = NULL;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            goto __pyx_L89_unpacking_done;
            __pyx_L88_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_18 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 1034, __pyx_L1_error)
            __pyx_L89_unpacking_done:;
          }
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
          __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_14);
          __pyx_t_14 = 0;

          /* "pyquant/cpeaks.pyx":1035
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if shift and j[1]*0.9 > i[1]:             # <<<<<<<<<<<<<<
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:
 */
          __pyx_t_12 = (__pyx_v_shift != 0);
          if (__pyx_t_12) {
          } else {
            __pyx_t_5 = __pyx_t_12;
            goto __pyx_L91_bool_binop_done;
          }
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_j, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1035, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_14 = PyNumber_Multiply(__pyx_t_9, __pyx_float_0_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1035, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_i, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1035, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = PyObject_RichCompare(__pyx_t_14, __pyx_t_9, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1035, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1035, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_5 = __pyx_t_12;
          __pyx_L91_bool_binop_done:;
          if (__pyx_t_5) {

            /* "pyquant/cpeaks.pyx":1036
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if shift and j[1]*0.9 > i[1]:
 *                         remove = True             # <<<<<<<<<<<<<<
 *                     elif shift is False and j[1] < i[1]*0.9:
 *                         if shift:
 */
            __pyx_v_remove = 1;

            /* "pyquant/cpeaks.pyx":1035
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 *                     if shift and j[1]*0.9 > i[1]:             # <<<<<<<<<<<<<<
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:
 */
            goto __pyx_L90;
          }

          /* "pyquant/cpeaks.pyx":1037
 *                     if shift and j[1]*0.9 > i[1]:
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:             # <<<<<<<<<<<<<<
 *                         if shift:
 *                             remove = True
 */
          __pyx_t_12 = ((__pyx_v_shift == 0) != 0);
          if (__pyx_t_12) {
          } else {
            __pyx_t_5 = __pyx_t_12;
            goto __pyx_L93_bool_binop_done;
          }
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_j, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1037, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_i, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1037, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_14 = PyNumber_Multiply(__pyx_t_9, __pyx_float_0_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1037, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyObject_RichCompare(__pyx_t_1, __pyx_t_14, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1037, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1037, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_5 = __pyx_t_12;
          __pyx_L93_bool_binop_done:;
          if (__pyx_t_5) {

            /* "pyquant/cpeaks.pyx":1038
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:
 *                         if shift:             # <<<<<<<<<<<<<<
 *                             remove = True
 *                         else:
 */
            __pyx_t_5 = (__pyx_v_shift != 0);
            if (__pyx_t_5) {

              /* "pyquant/cpeaks.pyx":1039
 *                     elif shift is False and j[1] < i[1]*0.9:
 *                         if shift:
 *                             remove = True             # <<<<<<<<<<<<<<
 *                         else:
 *                             shift = True
 */
              __pyx_v_remove = 1;

              /* "pyquant/cpeaks.pyx":1038
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:
 *                         if shift:             # <<<<<<<<<<<<<<
 *                             remove = True
 *                         else:
 */
              goto __pyx_L95;
            }

            /* "pyquant/cpeaks.pyx":1041
 *                             remove = True
 *                         else:
 *                             shift = True             # <<<<<<<<<<<<<<
 *                     if remove:
 *                         if debug:
 */
            /*else*/ {
              __pyx_v_shift = 1;
            }
            __pyx_L95:;

            /* "pyquant/cpeaks.pyx":1037
 *                     if shift and j[1]*0.9 > i[1]:
 *                         remove = True
 *                     elif shift is False and j[1] < i[1]*0.9:             # <<<<<<<<<<<<<<
 *                         if shift:
 *                             remove = True
 */
          }
          __pyx_L90:;

          /* "pyquant/cpeaks.pyx":1042
 *                         else:
 *                             shift = True
 *                     if remove:             # <<<<<<<<<<<<<<
 *                         if debug:
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 */
          __pyx_t_5 = (__pyx_v_remove != 0);
          if (__pyx_t_5) {

            /* "pyquant/cpeaks.pyx":1043
 *                             shift = True
 *                     if remove:
 *                         if debug:             # <<<<<<<<<<<<<<
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 */
            __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_debug); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1043, __pyx_L1_error)
            if (__pyx_t_5) {

              /* "pyquant/cpeaks.pyx":1044
 *                     if remove:
 *                         if debug:
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)             # <<<<<<<<<<<<<<
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])
 */
              __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1044, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_14 = PyTuple_New(4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1044, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_INCREF(__pyx_kp_s_pattern2_2_loss);
              __Pyx_GIVEREF(__pyx_kp_s_pattern2_2_loss);
              PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_kp_s_pattern2_2_loss);
              __Pyx_INCREF(__pyx_v_label);
              __Pyx_GIVEREF(__pyx_v_label);
              PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_label);
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_9);
              __Pyx_INCREF(__pyx_v_isotope_pattern);
              __Pyx_GIVEREF(__pyx_v_isotope_pattern);
              PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_v_isotope_pattern);
              __pyx_t_9 = 0;
              if (__Pyx_PrintOne(0, __pyx_t_14) < 0) __PYX_ERR(0, 1044, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

              /* "pyquant/cpeaks.pyx":1043
 *                             shift = True
 *                     if remove:
 *                         if debug:             # <<<<<<<<<<<<<<
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 */
            }

            /* "pyquant/cpeaks.pyx":1045
 *                         if debug:
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])             # <<<<<<<<<<<<<<
 *                         micro_dict.pop(j[0])
 *                         ppm_dict.pop(j[0])
 */
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_env_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1045, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1045, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_3 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
              if (likely(__pyx_t_3)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                __Pyx_INCREF(__pyx_t_3);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_9, function);
              }
            }
            if (!__pyx_t_3) {
              __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1045, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_GOTREF(__pyx_t_14);
            } else {
              __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1045, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_3); __pyx_t_3 = NULL;
              __Pyx_GIVEREF(__pyx_t_1);
              PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_t_1);
              __pyx_t_1 = 0;
              __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_16, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1045, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            }
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

            /* "pyquant/cpeaks.pyx":1046
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])             # <<<<<<<<<<<<<<
 *                         ppm_dict.pop(j[0])
 * 
 */
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_micro_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1046, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1046, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_16);
            __pyx_t_1 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
              __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
              if (likely(__pyx_t_1)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                __Pyx_INCREF(__pyx_t_1);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_9, function);
              }
            }
            if (!__pyx_t_1) {
              __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_16); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1046, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_14);
            } else {
              __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1046, __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 = NULL;
              __Pyx_GIVEREF(__pyx_t_16);
              PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_16);
              __pyx_t_16 = 0;
              __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_3, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1046, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

            /* "pyquant/cpeaks.pyx":1047
 *                         env_dict.pop(j[0])
 *                         micro_dict.pop(j[0])
 *                         ppm_dict.pop(j[0])             # <<<<<<<<<<<<<<
 * 
 *     return {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}
 */
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_ppm_dict, __pyx_n_s_pop); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1047, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_j, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1047, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_16 = NULL;
            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
              __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9);
              if (likely(__pyx_t_16)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                __Pyx_INCREF(__pyx_t_16);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_9, function);
              }
            }
            if (!__pyx_t_16) {
              __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1047, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_14);
            } else {
              __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_16); __pyx_t_16 = NULL;
              __Pyx_GIVEREF(__pyx_t_3);
              PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_3);
              __pyx_t_3 = 0;
              __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_1, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1047, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            }
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

            /* "pyquant/cpeaks.pyx":1042
 *                         else:
 *                             shift = True
 *                     if remove:             # <<<<<<<<<<<<<<
 *                         if debug:
 *                             print('pattern2.2 loss', label, j[0], isotope_pattern)
 */
          }

          /* "pyquant/cpeaks.pyx":1034
 *             elif isotope_pattern[1][1] > isotope_pattern[0][1]:
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):             # <<<<<<<<<<<<<<
 *                     if shift and j[1]*0.9 > i[1]:
 *                         remove = True
 */
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pyquant/cpeaks.pyx":1032
 *             #  |  |  |  |
 * 
 *             elif isotope_pattern[1][1] > isotope_pattern[0][1]:             # <<<<<<<<<<<<<<
 *                 shift = False
 *                 for i,j in zip(isotope_pattern, isotope_pattern[1:]):
 */
      }
      __pyx_L78:;

      /* "pyquant/cpeaks.pyx":1004
 *         # are we monotonically decreasing?
 *         remove = False
 *         if len(isotope_pattern) > 2:             # <<<<<<<<<<<<<<
 *             # check if the 2nd isotope is smaller than the first. This is a classical case looking like:
 *             #
 */
    }

    /* "pyquant/cpeaks.pyx":1001
 *     # rebuild the pattern after contaminants are removed
 *     isotope_pattern = [(isotope_index, isotope_dict['int']) for isotope_index, isotope_dict in micro_dict.items()]
 *     if theo_dist is None:             # <<<<<<<<<<<<<<
 *         # are we monotonically decreasing?
 *         remove = False
 */
  }

  /* "pyquant/cpeaks.pyx":1049
 *                         ppm_dict.pop(j[0])
 * 
 *     return {'envelope': env_dict, 'micro_envelopes': micro_dict, 'ppms': ppm_dict}             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_envelope, __pyx_v_env_dict) < 0) __PYX_ERR(0, 1049, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_micro_envelopes, __pyx_v_micro_dict) < 0) __PYX_ERR(0, 1049, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ppms, __pyx_v_ppm_dict) < 0) __PYX_ERR(0, 1049, __pyx_L1_error)
  __pyx_r = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pyquant/cpeaks.pyx":784
 *     return out
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,             # <<<<<<<<<<<<<<
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_16);
  { 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_non_empty.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findEnvelope", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_non_empty.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_start_mz);
  __Pyx_XDECREF(__pyx_v_initial_mz);
  __Pyx_XDECREF(__pyx_v_env_dict);
  __Pyx_XDECREF(__pyx_v_micro_dict);
  __Pyx_XDECREF(__pyx_v_ppm_dict);
  __Pyx_XDECREF(__pyx_v_empty_dict);
  __Pyx_XDECREF((PyObject *)__pyx_v_non_empty);
  __Pyx_XDECREF(__pyx_v_first_mz);
  __Pyx_XDECREF(__pyx_v_isotope_index);
  __Pyx_XDECREF(__pyx_v_start_index);
  __Pyx_XDECREF(__pyx_v_start_info);
  __Pyx_XDECREF(__pyx_v_start_error);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_valid_locations2);
  __Pyx_XDECREF(__pyx_v_contaminant_bounds);
  __Pyx_XDECREF(__pyx_v_contaminant_int);
  __Pyx_XDECREF(__pyx_v_pos);
  __Pyx_XDECREF(__pyx_v_offset);
  __Pyx_XDECREF(__pyx_v_last_displacement);
  __Pyx_XDECREF(__pyx_v_valid_locations);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_closest_contaminant);
  __Pyx_XDECREF(__pyx_v_closest_contaminant_index);
  __Pyx_XDECREF(__pyx_v_current_loc);
  __Pyx_XDECREF(__pyx_v_displacement);
  __Pyx_XDECREF(__pyx_v_valid_keys);
  __Pyx_XDECREF(__pyx_v_best_locations);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_empty_index);
  __Pyx_XDECREF(__pyx_v_micro_index);
  __Pyx_XDECREF(__pyx_v_isotope_tolerance);
  __Pyx_XDECREF(__pyx_v_micro_bounds);
  __Pyx_XDECREF(__pyx_v_isotope_pattern);
  __Pyx_XDECREF(__pyx_v_isotope_intensity);
  __Pyx_XDECREF(__pyx_v_j);
  __Pyx_XDECREF(__pyx_v_isotope_dict);
  __Pyx_XDECREF(__pyx_v_theo_mz);
  __Pyx_XDECREF(__pyx_v_max_mz);
  __Pyx_XDECREF(__pyx_v_isotope_ppms);
  __Pyx_XDECREF(__pyx_v_last_precursor);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7pyquant_6cpeaks_31findEnvelope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_7pyquant_6cpeaks_31findEnvelope(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_xdata = 0;
  PyArrayObject *__pyx_v_ydata = 0;
  PyObject *__pyx_v_measured_mz = 0;
  PyObject *__pyx_v_theo_mz = 0;
  PyObject *__pyx_v_max_mz = 0;
  PyObject *__pyx_v_precursor_ppm = 0;
  PyObject *__pyx_v_isotope_ppm = 0;
  PyObject *__pyx_v_isotope_ppms = 0;
  PyObject *__pyx_v_charge = 0;
  PyObject *__pyx_v_debug = 0;
  PyObject *__pyx_v_isotope_offset = 0;
  PyObject *__pyx_v_isotopologue_limit = 0;
  PyObject *__pyx_v_theo_dist = 0;
  PyObject *__pyx_v_label = 0;
  PyObject *__pyx_v_skip_isotopes = 0;
  PyObject *__pyx_v_last_precursor = 0;
  PyObject *__pyx_v_quant_method = 0;
  PyObject *__pyx_v_reporter_mode = 0;
  PyObject *__pyx_v_fragment_scan = 0;
  PyObject *__pyx_v_centroid = 0;
  PyObject *__pyx_v_contaminant_search = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("findEnvelope (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xdata,&__pyx_n_s_ydata,&__pyx_n_s_measured_mz,&__pyx_n_s_theo_mz,&__pyx_n_s_max_mz,&__pyx_n_s_precursor_ppm,&__pyx_n_s_isotope_ppm,&__pyx_n_s_isotope_ppms,&__pyx_n_s_charge,&__pyx_n_s_debug,&__pyx_n_s_isotope_offset,&__pyx_n_s_isotopologue_limit,&__pyx_n_s_theo_dist,&__pyx_n_s_label,&__pyx_n_s_skip_isotopes,&__pyx_n_s_last_precursor,&__pyx_n_s_quant_method,&__pyx_n_s_reporter_mode,&__pyx_n_s_fragment_scan,&__pyx_n_s_centroid,&__pyx_n_s_contaminant_search,0};
    PyObject* values[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = ((PyObject *)__pyx_int_5);
    values[6] = ((PyObject *)__pyx_float_2_5);
    values[7] = ((PyObject *)Py_None);
    values[8] = ((PyObject *)__pyx_int_2);
    values[9] = ((PyObject *)Py_False);
    values[10] = ((PyObject *)__pyx_int_0);
    values[11] = ((PyObject *)__pyx_int_neg_1);

    /* "pyquant/cpeaks.pyx":785
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,             # <<<<<<<<<<<<<<
 *                  centroid=False, contaminant_search=True):
 *     # returns the envelope of isotopic peaks as well as micro envelopes  of each individual cluster
 */
    values[12] = ((PyObject *)Py_None);
    values[13] = ((PyObject *)Py_None);
    values[14] = ((PyObject *)Py_None);
    values[15] = ((PyObject *)Py_None);
    values[16] = ((PyObject *)__pyx_n_s_integrate);
    values[17] = ((PyObject *)Py_False);
    values[18] = ((PyObject *)Py_False);

    /* "pyquant/cpeaks.pyx":786
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):             # <<<<<<<<<<<<<<
 *     # returns the envelope of isotopic peaks as well as micro envelopes  of each individual cluster
 *     cdef float spacing = NEUTRON/float(charge)
 */
    values[19] = ((PyObject *)Py_False);
    values[20] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20);
        case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19);
        case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18);
        case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17);
        case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16);
        case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        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_xdata)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ydata)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("findEnvelope", 0, 2, 21, 1); __PYX_ERR(0, 784, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_measured_mz);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_theo_mz);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_mz);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_precursor_ppm);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_isotope_ppm);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_isotope_ppms);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_charge);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_debug);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_isotope_offset);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_isotopologue_limit);
          if (value) { values[11] = value; kw_args--; }
        }
        case 12:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_theo_dist);
          if (value) { values[12] = value; kw_args--; }
        }
        case 13:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_label);
          if (value) { values[13] = value; kw_args--; }
        }
        case 14:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_skip_isotopes);
          if (value) { values[14] = value; kw_args--; }
        }
        case 15:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_last_precursor);
          if (value) { values[15] = value; kw_args--; }
        }
        case 16:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quant_method);
          if (value) { values[16] = value; kw_args--; }
        }
        case 17:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reporter_mode);
          if (value) { values[17] = value; kw_args--; }
        }
        case 18:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fragment_scan);
          if (value) { values[18] = value; kw_args--; }
        }
        case 19:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centroid);
          if (value) { values[19] = value; kw_args--; }
        }
        case 20:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_contaminant_search);
          if (value) { values[20] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "findEnvelope") < 0)) __PYX_ERR(0, 784, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20);
        case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19);
        case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18);
        case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17);
        case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16);
        case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xdata = ((PyArrayObject *)values[0]);
    __pyx_v_ydata = ((PyArrayObject *)values[1]);
    __pyx_v_measured_mz = values[2];
    __pyx_v_theo_mz = values[3];
    __pyx_v_max_mz = values[4];
    __pyx_v_precursor_ppm = values[5];
    __pyx_v_isotope_ppm = values[6];
    __pyx_v_isotope_ppms = values[7];
    __pyx_v_charge = values[8];
    __pyx_v_debug = values[9];
    __pyx_v_isotope_offset = values[10];
    __pyx_v_isotopologue_limit = values[11];
    __pyx_v_theo_dist = values[12];
    __pyx_v_label = values[13];
    __pyx_v_skip_isotopes = values[14];
    __pyx_v_last_precursor = values[15];
    __pyx_v_quant_method = values[16];
    __pyx_v_reporter_mode = values[17];
    __pyx_v_fragment_scan = values[18];
    __pyx_v_centroid = values[19];
    __pyx_v_contaminant_search = values[20];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("findEnvelope", 0, 2, 21, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 784, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pyquant.cpeaks.findEnvelope", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_xdata), __pyx_ptype_5numpy_ndarray, 1, "xdata", 0))) __PYX_ERR(0, 784, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ydata), __pyx_ptype_5numpy_ndarray, 1, "ydata", 0))) __PYX_ERR(0, 784, __pyx_L1_error)
  __pyx_r = __pyx_pf_7pyquant_6cpeaks_30findEnvelope(__pyx_self, __pyx_v_xdata, __pyx_v_ydata, __pyx_v_measured_mz, __pyx_v_theo_mz, __pyx_v_max_mz, __pyx_v_precursor_ppm, __pyx_v_isotope_ppm, __pyx_v_isotope_ppms, __pyx_v_charge, __pyx_v_debug, __pyx_v_isotope_offset, __pyx_v_isotopologue_limit, __pyx_v_theo_dist, __pyx_v_label, __pyx_v_skip_isotopes, __pyx_v_last_precursor, __pyx_v_quant_method, __pyx_v_reporter_mode, __pyx_v_fragment_scan, __pyx_v_centroid, __pyx_v_contaminant_search);

  /* "pyquant/cpeaks.pyx":784
 *     return out
 * 
 * cpdef dict findEnvelope(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, measured_mz=None, theo_mz=None, max_mz=None, precursor_ppm=5, isotope_ppm=2.5, isotope_ppms=None, charge=2, debug=False,             # <<<<<<<<<<<<<<
 *                  isotope_offset=0, isotopologue_limit=-1, theo_dist=None, label=None, skip_isotopes=None, last_precursor=None, quant_method='integrate', reporter_mode=False, fragment_scan=False,
 *                  centroid=False, contaminant_search=True):
 */

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

static PyObject *__pyx_pf_7pyquant_6cpeaks_30findEnvelope(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_xdata, PyArrayObject *__pyx_v_ydata, PyObject *__pyx_v_measured_mz, PyObject *__pyx_v_theo_mz, PyObject *__pyx_v_max_mz, PyObject *__pyx_v_precursor_ppm, PyObject *__pyx_v_isotope_ppm, PyObject *__pyx_v_isotope_ppms, PyObject *__pyx_v_charge, PyObject *__pyx_v_debug, PyObject *__pyx_v_isotope_offset, PyObject *__pyx_v_isotopologue_limit, PyObject *__pyx_v_theo_dist, PyObject *__pyx_v_label, PyObject *__pyx_v_skip_isotopes, PyObject *__pyx_v_last_precursor, PyObject *__pyx_v_quant_method, PyObject *__pyx_v_reporter_mode, PyObject *__pyx_v_fragment_scan, PyObject *__pyx_v_centroid, PyObject *__pyx_v_contaminant_search) {
  __Pyx_LocalBuf_ND __pyx_pybuffernd_xdata;
  __Pyx_Buffer __pyx_pybuffer_xdata;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ydata;
  __Pyx_Buffer __pyx_pybuffer_ydata;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_7pyquant_6cpeaks_findEnvelope __pyx_t_2;
  __Pyx_RefNannySetupContext("findEnvelope", 0);
  __pyx_pybuffer_xdata.pybuffer.buf = NULL;
  __pyx_pybuffer_xdata.refcount = 0;
  __pyx_pybuffernd_xdata.data = NULL;
  __pyx_pybuffernd_xdata.rcbuffer = &__pyx_pybuffer_xdata;
  __pyx_pybuffer_ydata.pybuffer.buf = NULL;
  __pyx_pybuffer_ydata.refcount = 0;
  __pyx_pybuffernd_ydata.data = NULL;
  __pyx_pybuffernd_ydata.rcbuffer = &__pyx_pybuffer_ydata;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer, (PyObject*)__pyx_v_xdata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 784, __pyx_L1_error)
  }
  __pyx_pybuffernd_xdata.diminfo[0].strides = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xdata.diminfo[0].shape = __pyx_pybuffernd_xdata.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer, (PyObject*)__pyx_v_ydata, &__Pyx_TypeInfo_nn___pyx_t_7pyquant_6cpeaks_FLOAT_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 784, __pyx_L1_error)
  }
  __pyx_pybuffernd_ydata.diminfo[0].strides = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ydata.diminfo[0].shape = __pyx_pybuffernd_ydata.rcbuffer->pybuffer.shape[0];
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 19;
  __pyx_t_2.measured_mz = __pyx_v_measured_mz;
  __pyx_t_2.theo_mz = __pyx_v_theo_mz;
  __pyx_t_2.max_mz = __pyx_v_max_mz;
  __pyx_t_2.precursor_ppm = __pyx_v_precursor_ppm;
  __pyx_t_2.isotope_ppm = __pyx_v_isotope_ppm;
  __pyx_t_2.isotope_ppms = __pyx_v_isotope_ppms;
  __pyx_t_2.charge = __pyx_v_charge;
  __pyx_t_2.debug = __pyx_v_debug;
  __pyx_t_2.isotope_offset = __pyx_v_isotope_offset;
  __pyx_t_2.isotopologue_limit = __pyx_v_isotopologue_limit;
  __pyx_t_2.theo_dist = __pyx_v_theo_dist;
  __pyx_t_2.label = __pyx_v_label;
  __pyx_t_2.skip_isotopes = __pyx_v_skip_isotopes;
  __pyx_t_2.last_precursor = __pyx_v_last_precursor;
  __pyx_t_2.quant_method = __pyx_v_quant_method;
  __pyx_t_2.reporter_mode = __pyx_v_reporter_mode;
  __pyx_t_2.fragment_scan = __pyx_v_fragment_scan;
  __pyx_t_2.centroid = __pyx_v_centroid;
  __pyx_t_2.contaminant_search = __pyx_v_contaminant_search;
  __pyx_t_1 = __pyx_f_7pyquant_6cpeaks_findEnvelope(__pyx_v_xdata, __pyx_v_ydata, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { 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_xdata.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pyquant.cpeaks.findEnvelope", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xdata.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ydata.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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);
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__33, 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)

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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")
 */
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__34, 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)

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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")
 */
  }

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

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

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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]);
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__35, 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)

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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")
 */
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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
 */
  }

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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]) = '^';

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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';
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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):
 */
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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
 */
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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();
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(1, 796, __pyx_L1_error)
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__36, 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)

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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")
 * 
 */
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__37, 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)

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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")
 */
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

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

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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);
    }

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

        /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__38, 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)

        /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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.")
 * 
 */
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
      }

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

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

      /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
    }

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

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

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:;

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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();
}

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

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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) {

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;

    /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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:
 */
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
  }

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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;
}

static struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *__pyx_freelist_7pyquant_6cpeaks___pyx_scope_struct__findMicro[8];
static int __pyx_freecount_7pyquant_6cpeaks___pyx_scope_struct__findMicro = 0;

static PyObject *__pyx_tp_new_7pyquant_6cpeaks___pyx_scope_struct__findMicro(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7pyquant_6cpeaks___pyx_scope_struct__findMicro > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro)))) {
    o = (PyObject*)__pyx_freelist_7pyquant_6cpeaks___pyx_scope_struct__findMicro[--__pyx_freecount_7pyquant_6cpeaks___pyx_scope_struct__findMicro];
    memset(o, 0, sizeof(struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro));
    (void) PyObject_INIT(o, t);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_7pyquant_6cpeaks___pyx_scope_struct__findMicro(PyObject *o) {
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7pyquant_6cpeaks___pyx_scope_struct__findMicro < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro)))) {
    __pyx_freelist_7pyquant_6cpeaks___pyx_scope_struct__findMicro[__pyx_freecount_7pyquant_6cpeaks___pyx_scope_struct__findMicro++] = ((struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static PyTypeObject __pyx_type_7pyquant_6cpeaks___pyx_scope_struct__findMicro = {
  PyVarObject_HEAD_INIT(0, 0)
  "pyquant.cpeaks.__pyx_scope_struct__findMicro", /*tp_name*/
  sizeof(struct __pyx_obj_7pyquant_6cpeaks___pyx_scope_struct__findMicro), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_7pyquant_6cpeaks___pyx_scope_struct__findMicro, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_7pyquant_6cpeaks___pyx_scope_struct__findMicro, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {"gauss_ndim", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_1gauss_ndim, METH_VARARGS|METH_KEYWORDS, 0},
  {"gauss_func", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_3gauss_func, METH_VARARGS|METH_KEYWORDS, 0},
  {"bigauss_jac", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_5bigauss_jac, METH_VARARGS|METH_KEYWORDS, 0},
  {"gauss_jac", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_7gauss_jac, METH_VARARGS|METH_KEYWORDS, 0},
  {"bigauss_ndim", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_9bigauss_ndim, METH_VARARGS|METH_KEYWORDS, 0},
  {"bigauss_func", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_11bigauss_func, METH_VARARGS|METH_KEYWORDS, 0},
  {"fixedMeanFit", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_13fixedMeanFit, METH_VARARGS|METH_KEYWORDS, 0},
  {"fixedMeanFit2", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_15fixedMeanFit2, METH_VARARGS|METH_KEYWORDS, 0},
  {"basin_stepper", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_17basin_stepper, METH_O, 0},
  {"findAllPeaks", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_19findAllPeaks, METH_VARARGS|METH_KEYWORDS, 0},
  {"get_ppm", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_21get_ppm, METH_VARARGS|METH_KEYWORDS, 0},
  {"findEnvelope", (PyCFunction)__pyx_pw_7pyquant_6cpeaks_31findEnvelope, METH_VARARGS|METH_KEYWORDS, 0},
  {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
    "cpeaks",
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_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_kp_s_L_BFGS_B, __pyx_k_L_BFGS_B, sizeof(__pyx_k_L_BFGS_B), 0, 0, 1, 0},
  {&__pyx_n_s_NEUTRON, __pyx_k_NEUTRON, sizeof(__pyx_k_NEUTRON), 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_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s_SLSQP, __pyx_k_SLSQP, sizeof(__pyx_k_SLSQP), 0, 0, 1, 1},
  {&__pyx_n_s_TNC, __pyx_k_TNC, sizeof(__pyx_k_TNC), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 0, 1, 0},
  {&__pyx_kp_s__20, __pyx_k__20, sizeof(__pyx_k__20), 0, 0, 1, 0},
  {&__pyx_kp_s__23, __pyx_k__23, sizeof(__pyx_k__23), 0, 0, 1, 0},
  {&__pyx_n_s_abs, __pyx_k_abs, sizeof(__pyx_k_abs), 0, 0, 1, 1},
  {&__pyx_n_s_amplitude_filter, __pyx_k_amplitude_filter, sizeof(__pyx_k_amplitude_filter), 0, 0, 1, 1},
  {&__pyx_n_s_analyzing, __pyx_k_analyzing, sizeof(__pyx_k_analyzing), 0, 0, 1, 1},
  {&__pyx_n_s_any, __pyx_k_any, sizeof(__pyx_k_any), 0, 0, 1, 1},
  {&__pyx_n_s_argmax, __pyx_k_argmax, sizeof(__pyx_k_argmax), 0, 0, 1, 1},
  {&__pyx_n_s_argrelmax, __pyx_k_argrelmax, sizeof(__pyx_k_argrelmax), 0, 0, 1, 1},
  {&__pyx_n_s_argrelmin, __pyx_k_argrelmin, sizeof(__pyx_k_argrelmin), 0, 0, 1, 1},
  {&__pyx_n_s_argsort, __pyx_k_argsort, sizeof(__pyx_k_argsort), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_attrgetter, __pyx_k_attrgetter, sizeof(__pyx_k_attrgetter), 0, 0, 1, 1},
  {&__pyx_n_s_average, __pyx_k_average, sizeof(__pyx_k_average), 0, 0, 1, 1},
  {&__pyx_n_s_axis, __pyx_k_axis, sizeof(__pyx_k_axis), 0, 0, 1, 1},
  {&__pyx_n_s_becomes, __pyx_k_becomes, sizeof(__pyx_k_becomes), 0, 0, 1, 1},
  {&__pyx_kp_s_best, __pyx_k_best, sizeof(__pyx_k_best), 0, 0, 1, 0},
  {&__pyx_kp_s_best_fit, __pyx_k_best_fit, sizeof(__pyx_k_best_fit), 0, 0, 1, 0},
  {&__pyx_n_s_bic, __pyx_k_bic, sizeof(__pyx_k_bic), 0, 0, 1, 1},
  {&__pyx_n_s_bigauss_fit, __pyx_k_bigauss_fit, sizeof(__pyx_k_bigauss_fit), 0, 0, 1, 1},
  {&__pyx_n_s_bigauss_func, __pyx_k_bigauss_func, sizeof(__pyx_k_bigauss_func), 0, 0, 1, 1},
  {&__pyx_n_s_bigauss_jac, __pyx_k_bigauss_jac, sizeof(__pyx_k_bigauss_jac), 0, 0, 1, 1},
  {&__pyx_n_s_bounds, __pyx_k_bounds, sizeof(__pyx_k_bounds), 0, 0, 1, 1},
  {&__pyx_n_s_calc_start_mz, __pyx_k_calc_start_mz, sizeof(__pyx_k_calc_start_mz), 0, 0, 1, 1},
  {&__pyx_n_s_centroid, __pyx_k_centroid, sizeof(__pyx_k_centroid), 0, 0, 1, 1},
  {&__pyx_n_s_charge, __pyx_k_charge, sizeof(__pyx_k_charge), 0, 0, 1, 1},
  {&__pyx_kp_s_checking, __pyx_k_checking, sizeof(__pyx_k_checking), 0, 0, 1, 0},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_concatenate, __pyx_k_concatenate, sizeof(__pyx_k_concatenate), 0, 0, 1, 1},
  {&__pyx_n_s_constant, __pyx_k_constant, sizeof(__pyx_k_constant), 0, 0, 1, 1},
  {&__pyx_n_s_contains_rt, __pyx_k_contains_rt, sizeof(__pyx_k_contains_rt), 0, 0, 1, 1},
  {&__pyx_kp_s_contaminant_loss, __pyx_k_contaminant_loss, sizeof(__pyx_k_contaminant_loss), 0, 0, 1, 0},
  {&__pyx_n_s_contaminant_search, __pyx_k_contaminant_search, sizeof(__pyx_k_contaminant_search), 0, 0, 1, 1},
  {&__pyx_n_s_convolve, __pyx_k_convolve, sizeof(__pyx_k_convolve), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_kp_s_data_is_empty, __pyx_k_data_is_empty, sizeof(__pyx_k_data_is_empty), 0, 0, 1, 0},
  {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1},
  {&__pyx_n_s_deepcopy, __pyx_k_deepcopy, sizeof(__pyx_k_deepcopy), 0, 0, 1, 1},
  {&__pyx_n_s_df_empty_index, __pyx_k_df_empty_index, sizeof(__pyx_k_df_empty_index), 0, 0, 1, 1},
  {&__pyx_n_s_diff, __pyx_k_diff, sizeof(__pyx_k_diff), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_kp_s_empty_start_info, __pyx_k_empty_start_info, sizeof(__pyx_k_empty_start_info), 0, 0, 1, 0},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_envelope, __pyx_k_envelope, sizeof(__pyx_k_envelope), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_n_s_exp, __pyx_k_exp, sizeof(__pyx_k_exp), 0, 0, 1, 1},
  {&__pyx_n_s_fabs, __pyx_k_fabs, sizeof(__pyx_k_fabs), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_filter, __pyx_k_filter, sizeof(__pyx_k_filter), 0, 0, 1, 1},
  {&__pyx_kp_s_final_peaks, __pyx_k_final_peaks, sizeof(__pyx_k_final_peaks), 0, 0, 1, 0},
  {&__pyx_n_s_findAllPeaks, __pyx_k_findAllPeaks, sizeof(__pyx_k_findAllPeaks), 0, 0, 1, 1},
  {&__pyx_n_s_findMicro, __pyx_k_findMicro, sizeof(__pyx_k_findMicro), 0, 0, 1, 1},
  {&__pyx_n_s_findMicro_locals_lambda, __pyx_k_findMicro_locals_lambda, sizeof(__pyx_k_findMicro_locals_lambda), 0, 0, 1, 1},
  {&__pyx_n_s_find_nearest, __pyx_k_find_nearest, sizeof(__pyx_k_find_nearest), 0, 0, 1, 1},
  {&__pyx_n_s_find_nearest_index, __pyx_k_find_nearest_index, sizeof(__pyx_k_find_nearest_index), 0, 0, 1, 1},
  {&__pyx_n_s_find_nearest_indices, __pyx_k_find_nearest_indices, sizeof(__pyx_k_find_nearest_indices), 0, 0, 1, 1},
  {&__pyx_n_s_fit, __pyx_k_fit, sizeof(__pyx_k_fit), 0, 0, 1, 1},
  {&__pyx_kp_s_fitting_error, __pyx_k_fitting_error, sizeof(__pyx_k_fitting_error), 0, 0, 1, 0},
  {&__pyx_kp_s_fitting_results, __pyx_k_fitting_results, sizeof(__pyx_k_fitting_results), 0, 0, 1, 0},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_format_exc, __pyx_k_format_exc, sizeof(__pyx_k_format_exc), 0, 0, 1, 1},
  {&__pyx_kp_s_found, __pyx_k_found, sizeof(__pyx_k_found), 0, 0, 1, 0},
  {&__pyx_n_s_fragment_scan, __pyx_k_fragment_scan, sizeof(__pyx_k_fragment_scan), 0, 0, 1, 1},
  {&__pyx_n_s_ftol, __pyx_k_ftol, sizeof(__pyx_k_ftol), 0, 0, 1, 1},
  {&__pyx_n_s_fun, __pyx_k_fun, sizeof(__pyx_k_fun), 0, 0, 1, 1},
  {&__pyx_n_s_gauss_func, __pyx_k_gauss_func, sizeof(__pyx_k_gauss_func), 0, 0, 1, 1},
  {&__pyx_n_s_gauss_jac, __pyx_k_gauss_jac, sizeof(__pyx_k_gauss_jac), 0, 0, 1, 1},
  {&__pyx_n_s_gaussian_filter1d, __pyx_k_gaussian_filter1d, sizeof(__pyx_k_gaussian_filter1d), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_gradient, __pyx_k_gradient, sizeof(__pyx_k_gradient), 0, 0, 1, 1},
  {&__pyx_n_s_guess, __pyx_k_guess, sizeof(__pyx_k_guess), 0, 0, 1, 1},
  {&__pyx_kp_s_guess_and_bounds, __pyx_k_guess_and_bounds, sizeof(__pyx_k_guess_and_bounds), 0, 0, 1, 0},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_idx, __pyx_k_idx, sizeof(__pyx_k_idx), 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_inf, __pyx_k_inf, sizeof(__pyx_k_inf), 0, 0, 1, 1},
  {&__pyx_n_s_int, __pyx_k_int, sizeof(__pyx_k_int), 0, 0, 1, 1},
  {&__pyx_n_s_int2, __pyx_k_int2, sizeof(__pyx_k_int2), 0, 0, 1, 1},
  {&__pyx_n_s_int_val, __pyx_k_int_val, sizeof(__pyx_k_int_val), 0, 0, 1, 1},
  {&__pyx_n_s_integrate, __pyx_k_integrate, sizeof(__pyx_k_integrate), 0, 0, 1, 1},
  {&__pyx_n_s_interp1d, __pyx_k_interp1d, sizeof(__pyx_k_interp1d), 0, 0, 1, 1},
  {&__pyx_n_s_intersection, __pyx_k_intersection, sizeof(__pyx_k_intersection), 0, 0, 1, 1},
  {&__pyx_n_s_isnan, __pyx_k_isnan, sizeof(__pyx_k_isnan), 0, 0, 1, 1},
  {&__pyx_n_s_isotope, __pyx_k_isotope, sizeof(__pyx_k_isotope), 0, 0, 1, 1},
  {&__pyx_n_s_isotope_offset, __pyx_k_isotope_offset, sizeof(__pyx_k_isotope_offset), 0, 0, 1, 1},
  {&__pyx_n_s_isotope_ppm, __pyx_k_isotope_ppm, sizeof(__pyx_k_isotope_ppm), 0, 0, 1, 1},
  {&__pyx_n_s_isotope_ppms, __pyx_k_isotope_ppms, sizeof(__pyx_k_isotope_ppms), 0, 0, 1, 1},
  {&__pyx_n_s_isotopologue_limit, __pyx_k_isotopologue_limit, sizeof(__pyx_k_isotopologue_limit), 0, 0, 1, 1},
  {&__pyx_n_s_itemgetter, __pyx_k_itemgetter, sizeof(__pyx_k_itemgetter), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  {&__pyx_n_s_jac, __pyx_k_jac, sizeof(__pyx_k_jac), 0, 0, 1, 1},
  {&__pyx_n_s_kaiser, __pyx_k_kaiser, sizeof(__pyx_k_kaiser), 0, 0, 1, 1},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_label, __pyx_k_label, sizeof(__pyx_k_label), 0, 0, 1, 1},
  {&__pyx_n_s_last_precursor, __pyx_k_last_precursor, sizeof(__pyx_k_last_precursor), 0, 0, 1, 1},
  {&__pyx_n_s_left, __pyx_k_left, sizeof(__pyx_k_left), 0, 0, 1, 1},
  {&__pyx_kp_s_left_is, __pyx_k_left_is, sizeof(__pyx_k_left_is), 0, 0, 1, 0},
  {&__pyx_n_s_log, __pyx_k_log, sizeof(__pyx_k_log), 0, 0, 1, 1},
  {&__pyx_n_s_lr, __pyx_k_lr, sizeof(__pyx_k_lr), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_mz, __pyx_k_max_mz, sizeof(__pyx_k_max_mz), 0, 0, 1, 1},
  {&__pyx_n_s_max_peaks, __pyx_k_max_peaks, sizeof(__pyx_k_max_peaks), 0, 0, 1, 1},
  {&__pyx_n_s_maxiter, __pyx_k_maxiter, sizeof(__pyx_k_maxiter), 0, 0, 1, 1},
  {&__pyx_n_s_measured_mz, __pyx_k_measured_mz, sizeof(__pyx_k_measured_mz), 0, 0, 1, 1},
  {&__pyx_n_s_method, __pyx_k_method, sizeof(__pyx_k_method), 0, 0, 1, 1},
  {&__pyx_n_s_micro_envelopes, __pyx_k_micro_envelopes, sizeof(__pyx_k_micro_envelopes), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_min_dist, __pyx_k_min_dist, sizeof(__pyx_k_min_dist), 0, 0, 1, 1},
  {&__pyx_n_s_minima, __pyx_k_minima, sizeof(__pyx_k_minima), 0, 0, 1, 1},
  {&__pyx_n_s_minimize, __pyx_k_minimize, sizeof(__pyx_k_minimize), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_mrm, __pyx_k_mrm, sizeof(__pyx_k_mrm), 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_x, __pyx_k_new_x, sizeof(__pyx_k_new_x), 0, 0, 1, 1},
  {&__pyx_n_s_new_y, __pyx_k_new_y, sizeof(__pyx_k_new_y), 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_n_s_observed, __pyx_k_observed, sizeof(__pyx_k_observed), 0, 0, 1, 1},
  {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1},
  {&__pyx_n_s_operator, __pyx_k_operator, sizeof(__pyx_k_operator), 0, 0, 1, 1},
  {&__pyx_kp_s_opt_conda_conda_bld_pyquant_ms, __pyx_k_opt_conda_conda_bld_pyquant_ms, sizeof(__pyx_k_opt_conda_conda_bld_pyquant_ms), 0, 0, 1, 0},
  {&__pyx_n_s_optimize, __pyx_k_optimize, sizeof(__pyx_k_optimize), 0, 0, 1, 1},
  {&__pyx_n_s_options, __pyx_k_options, sizeof(__pyx_k_options), 0, 0, 1, 1},
  {&__pyx_n_s_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 0, 1, 1},
  {&__pyx_n_s_out, __pyx_k_out, sizeof(__pyx_k_out), 0, 0, 1, 1},
  {&__pyx_n_s_params, __pyx_k_params, sizeof(__pyx_k_params), 0, 0, 1, 1},
  {&__pyx_kp_s_pattern2_1_loss, __pyx_k_pattern2_1_loss, sizeof(__pyx_k_pattern2_1_loss), 0, 0, 1, 0},
  {&__pyx_kp_s_pattern2_2_loss, __pyx_k_pattern2_2_loss, sizeof(__pyx_k_pattern2_2_loss), 0, 0, 1, 0},
  {&__pyx_n_s_peak, __pyx_k_peak, sizeof(__pyx_k_peak), 0, 0, 1, 1},
  {&__pyx_n_s_peak_index, __pyx_k_peak_index, sizeof(__pyx_k_peak_index), 0, 0, 1, 1},
  {&__pyx_n_s_peak_mean, __pyx_k_peak_mean, sizeof(__pyx_k_peak_mean), 0, 0, 1, 1},
  {&__pyx_n_s_peak_residuals, __pyx_k_peak_residuals, sizeof(__pyx_k_peak_residuals), 0, 0, 1, 1},
  {&__pyx_n_s_peak_width_end, __pyx_k_peak_width_end, sizeof(__pyx_k_peak_width_end), 0, 0, 1, 1},
  {&__pyx_n_s_peak_width_start, __pyx_k_peak_width_start, sizeof(__pyx_k_peak_width_start), 0, 0, 1, 1},
  {&__pyx_n_s_peaks, __pyx_k_peaks, sizeof(__pyx_k_peaks), 0, 0, 1, 1},
  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
  {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
  {&__pyx_n_s_ppm, __pyx_k_ppm, sizeof(__pyx_k_ppm), 0, 0, 1, 1},
  {&__pyx_n_s_ppms, __pyx_k_ppms, sizeof(__pyx_k_ppms), 0, 0, 1, 1},
  {&__pyx_n_s_precursor_ppm, __pyx_k_precursor_ppm, sizeof(__pyx_k_precursor_ppm), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_pyquant_cpeaks, __pyx_k_pyquant_cpeaks, sizeof(__pyx_k_pyquant_cpeaks), 0, 0, 1, 1},
  {&__pyx_n_s_pythomics_proteomics_config, __pyx_k_pythomics_proteomics_config, sizeof(__pyx_k_pythomics_proteomics_config), 0, 0, 1, 1},
  {&__pyx_n_s_quant_method, __pyx_k_quant_method, sizeof(__pyx_k_quant_method), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_reporter_mode, __pyx_k_reporter_mode, sizeof(__pyx_k_reporter_mode), 0, 0, 1, 1},
  {&__pyx_n_s_ret_dict, __pyx_k_ret_dict, sizeof(__pyx_k_ret_dict), 0, 0, 1, 1},
  {&__pyx_n_s_right, __pyx_k_right, sizeof(__pyx_k_right), 0, 0, 1, 1},
  {&__pyx_kp_s_right_is, __pyx_k_right_is, sizeof(__pyx_k_right_is), 0, 0, 1, 0},
  {&__pyx_n_s_rt_peak, __pyx_k_rt_peak, sizeof(__pyx_k_rt_peak), 0, 0, 1, 1},
  {&__pyx_n_s_same, __pyx_k_same, sizeof(__pyx_k_same), 0, 0, 1, 1},
  {&__pyx_n_s_scipy, __pyx_k_scipy, sizeof(__pyx_k_scipy), 0, 0, 1, 1},
  {&__pyx_n_s_scipy_interpolate, __pyx_k_scipy_interpolate, sizeof(__pyx_k_scipy_interpolate), 0, 0, 1, 1},
  {&__pyx_n_s_scipy_ndimage_filters, __pyx_k_scipy_ndimage_filters, sizeof(__pyx_k_scipy_ndimage_filters), 0, 0, 1, 1},
  {&__pyx_n_s_scipy_signal, __pyx_k_scipy_signal, sizeof(__pyx_k_scipy_signal), 0, 0, 1, 1},
  {&__pyx_n_s_search_index, __pyx_k_search_index, sizeof(__pyx_k_search_index), 0, 0, 1, 1},
  {&__pyx_n_s_search_value, __pyx_k_search_value, sizeof(__pyx_k_search_value), 0, 0, 1, 1},
  {&__pyx_n_s_searchsorted, __pyx_k_searchsorted, sizeof(__pyx_k_searchsorted), 0, 0, 1, 1},
  {&__pyx_n_s_side, __pyx_k_side, sizeof(__pyx_k_side), 0, 0, 1, 1},
  {&__pyx_n_s_sign, __pyx_k_sign, sizeof(__pyx_k_sign), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_skip_isotopes, __pyx_k_skip_isotopes, sizeof(__pyx_k_skip_isotopes), 0, 0, 1, 1},
  {&__pyx_n_s_snr, __pyx_k_snr, sizeof(__pyx_k_snr), 0, 0, 1, 1},
  {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1},
  {&__pyx_n_s_sorted, __pyx_k_sorted, sizeof(__pyx_k_sorted), 0, 0, 1, 1},
  {&__pyx_n_s_sorted_peaks, __pyx_k_sorted_peaks, sizeof(__pyx_k_sorted_peaks), 0, 0, 1, 1},
  {&__pyx_n_s_sorted_peaks2, __pyx_k_sorted_peaks2, sizeof(__pyx_k_sorted_peaks2), 0, 0, 1, 1},
  {&__pyx_n_s_spacing, __pyx_k_spacing, sizeof(__pyx_k_spacing), 0, 0, 1, 1},
  {&__pyx_n_s_sqrt, __pyx_k_sqrt, sizeof(__pyx_k_sqrt), 0, 0, 1, 1},
  {&__pyx_n_s_start_mz, __pyx_k_start_mz, sizeof(__pyx_k_start_mz), 0, 0, 1, 1},
  {&__pyx_n_s_std, __pyx_k_std, sizeof(__pyx_k_std), 0, 0, 1, 1},
  {&__pyx_n_s_stderr, __pyx_k_stderr, sizeof(__pyx_k_stderr), 0, 0, 1, 1},
  {&__pyx_n_s_success, __pyx_k_success, sizeof(__pyx_k_success), 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_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_theo_dist, __pyx_k_theo_dist, sizeof(__pyx_k_theo_dist), 0, 0, 1, 1},
  {&__pyx_n_s_theo_mz, __pyx_k_theo_mz, sizeof(__pyx_k_theo_mz), 0, 0, 1, 1},
  {&__pyx_n_s_theoretical, __pyx_k_theoretical, sizeof(__pyx_k_theoretical), 0, 0, 1, 1},
  {&__pyx_n_s_tol, __pyx_k_tol, sizeof(__pyx_k_tol), 0, 0, 1, 1},
  {&__pyx_n_s_tolerance, __pyx_k_tolerance, sizeof(__pyx_k_tolerance), 0, 0, 1, 1},
  {&__pyx_n_s_tolist, __pyx_k_tolist, sizeof(__pyx_k_tolist), 0, 0, 1, 1},
  {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_transpose, __pyx_k_transpose, sizeof(__pyx_k_transpose), 0, 0, 1, 1},
  {&__pyx_kp_s_unable_to_find_start_ion, __pyx_k_unable_to_find_start_ion, sizeof(__pyx_k_unable_to_find_start_ion), 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_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_weights, __pyx_k_weights, sizeof(__pyx_k_weights), 0, 0, 1, 1},
  {&__pyx_n_s_where, __pyx_k_where, sizeof(__pyx_k_where), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
  {&__pyx_n_s_xdata, __pyx_k_xdata, sizeof(__pyx_k_xdata), 0, 0, 1, 1},
  {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1},
  {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1},
  {&__pyx_n_s_ydata, __pyx_k_ydata, sizeof(__pyx_k_ydata), 0, 0, 1, 1},
  {&__pyx_n_s_ydata_original, __pyx_k_ydata_original, sizeof(__pyx_k_ydata_original), 0, 0, 1, 1},
  {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 16, __pyx_L1_error)
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 41, __pyx_L1_error)
  #if PY_MAJOR_VERSION >= 3
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 50, __pyx_L1_error)
  #else
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 50, __pyx_L1_error)
  #endif
  __pyx_builtin_any = __Pyx_GetBuiltinName(__pyx_n_s_any); if (!__pyx_builtin_any) __PYX_ERR(0, 123, __pyx_L1_error)
  __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 160, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 189, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 436, __pyx_L1_error)
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 530, __pyx_L1_error)
  __pyx_builtin_sorted = __Pyx_GetBuiltinName(__pyx_n_s_sorted); if (!__pyx_builtin_sorted) __PYX_ERR(0, 553, __pyx_L1_error)
  __pyx_builtin_filter = __Pyx_GetBuiltinName(__pyx_n_s_filter); if (!__pyx_builtin_filter) __PYX_ERR(0, 738, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(1, 231, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(1, 799, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

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

  /* "pyquant/cpeaks.pyx":31
 *     cdef np.ndarray[FLOAT_t, ndim=1] mus
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmas
 *     amps, mus, sigmas = params[::3], params[1::3], params[2::3]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma in zip(amps, mus, sigmas):
 */
  __pyx_slice_ = PySlice_New(Py_None, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice_);
  __Pyx_GIVEREF(__pyx_slice_);
  __pyx_slice__2 = PySlice_New(__pyx_int_1, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice__2)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__2);
  __Pyx_GIVEREF(__pyx_slice__2);
  __pyx_slice__3 = PySlice_New(__pyx_int_2, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice__3)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__3);
  __Pyx_GIVEREF(__pyx_slice__3);

  /* "pyquant/cpeaks.pyx":116
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmasl
 *     cdef np.ndarray[FLOAT_t, ndim=1] sigmasr
 *     amps, mus, sigmasl, sigmasr = params[::4], params[1::4], params[2::4], params[3::4]             # <<<<<<<<<<<<<<
 *     cdef np.ndarray[FLOAT_t, ndim=1] data = np.zeros(len(xdata))
 *     for amp, mu, sigma1, sigma2 in zip(amps, mus, sigmasl, sigmasr):
 */
  __pyx_slice__4 = PySlice_New(Py_None, Py_None, __pyx_int_4); if (unlikely(!__pyx_slice__4)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__4);
  __Pyx_GIVEREF(__pyx_slice__4);
  __pyx_slice__5 = PySlice_New(__pyx_int_1, Py_None, __pyx_int_4); if (unlikely(!__pyx_slice__5)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__5);
  __Pyx_GIVEREF(__pyx_slice__5);
  __pyx_slice__6 = PySlice_New(__pyx_int_2, Py_None, __pyx_int_4); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__6);
  __Pyx_GIVEREF(__pyx_slice__6);
  __pyx_slice__7 = PySlice_New(__pyx_int_3, Py_None, __pyx_int_4); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__7);
  __Pyx_GIVEREF(__pyx_slice__7);

  /* "pyquant/cpeaks.pyx":149
 * 
 *     ydata /= ydata.max()
 *     peak_left, peak_right = findPeak(convolve(ydata, kaiser(10, 14), mode='same'), peak_index)             # <<<<<<<<<<<<<<
 *     peak_min, peak_max = xdata[0], xdata[-1]
 *     # reset the fitting data to our bounds
 */
  __pyx_tuple__8 = PyTuple_Pack(2, __pyx_int_10, __pyx_int_14); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pyquant/cpeaks.pyx":167
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])             # <<<<<<<<<<<<<<
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 */
  __pyx_tuple__9 = PyTuple_Pack(2, __pyx_float_0_0, __pyx_float_1_0); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "pyquant/cpeaks.pyx":225
 * 
 *     mval = ydata.max()
 *     conv_y = gaussian_filter1d(convolve(ydata, kaiser(10, 14), mode='same'), 3, mode='constant')             # <<<<<<<<<<<<<<
 *     rel_peak = conv_y[peak_index]/conv_y.max()
 *     ydata /= mval
 */
  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_int_10, __pyx_int_14); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pyquant/cpeaks.pyx":242
 *     ydata = ydata[peak_left:peak_right]
 *     if ydata.sum() == 0:
 *         return None, None             # <<<<<<<<<<<<<<
 *     min_spacing = min(np.diff(xdata))/2
 *     lb = np.fabs(peak_loc-xdata[0])
 */
  __pyx_tuple__11 = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 242, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "pyquant/cpeaks.pyx":250
 *     if rb < min_spacing:
 *         rb = min_spacing*5
 *     bnds = np.array([(rel_peak*0.75, 1.01) if rel_peak > 0 else (0.0, 1.0), (xdata[0], xdata[-1]), (min_spacing, lb), (min_spacing, rb)])             # <<<<<<<<<<<<<<
 *     #print bnds, xdata, peak_loc
 *     average = np.average(xdata, weights=ydata)
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_float_0_0, __pyx_float_1_0); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pyquant/cpeaks.pyx":308
 * 
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):
 *     args[::1] += 0.1             # <<<<<<<<<<<<<<
 *     args[::2] += 0.1
 *     args[::3] += 0.05
 */
  __pyx_slice__13 = PySlice_New(Py_None, Py_None, __pyx_int_1); if (unlikely(!__pyx_slice__13)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__13);
  __Pyx_GIVEREF(__pyx_slice__13);

  /* "pyquant/cpeaks.pyx":309
 * cpdef basin_stepper(np.ndarray[FLOAT_t, ndim=1] args):
 *     args[::1] += 0.1
 *     args[::2] += 0.1             # <<<<<<<<<<<<<<
 *     args[::3] += 0.05
 *     args[::4] += 0.05
 */
  __pyx_slice__14 = PySlice_New(Py_None, Py_None, __pyx_int_2); if (unlikely(!__pyx_slice__14)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__14);
  __Pyx_GIVEREF(__pyx_slice__14);

  /* "pyquant/cpeaks.pyx":310
 *     args[::1] += 0.1
 *     args[::2] += 0.1
 *     args[::3] += 0.05             # <<<<<<<<<<<<<<
 *     args[::4] += 0.05
 *     return args
 */
  __pyx_slice__15 = PySlice_New(Py_None, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice__15)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__15);
  __Pyx_GIVEREF(__pyx_slice__15);

  /* "pyquant/cpeaks.pyx":311
 *     args[::2] += 0.1
 *     args[::3] += 0.05
 *     args[::4] += 0.05             # <<<<<<<<<<<<<<
 *     return args
 * 
 */
  __pyx_slice__16 = PySlice_New(Py_None, Py_None, __pyx_int_4); if (unlikely(!__pyx_slice__16)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__16);
  __Pyx_GIVEREF(__pyx_slice__16);

  /* "pyquant/cpeaks.pyx":338
 *     if filter:
 *         if len(ydata) >= 5:
 *             ydata_peaks = convolve(ydata_peaks, kaiser(10, 12), mode='same')#gaussian_filter1d(convolve(ydata_peaks, kaiser(10, 14), mode='same'), 3, mode='constant')##gaussian_filter1d(ydata_peaks, 3, mode='constant')             # <<<<<<<<<<<<<<
 *             ydata_peaks[ydata_peaks<0] = 0
 *     ydata_peaks[np.isnan(ydata_peaks)] = 0
 */
  __pyx_tuple__17 = PyTuple_Pack(2, __pyx_int_10, __pyx_int_12); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "pyquant/cpeaks.pyx":367
 *             # this selects the row peaks in ydata, reversed the sorting order (to be greatest to least), then
 *             # takes the number of peaks we allow and then sorts those peaks
 *             row_peaks = np.sort(row_peaks[np.argsort(ydata_peaks[row_peaks])[::-1]][:max_peaks])             # <<<<<<<<<<<<<<
 *             #peak_width_end += 1
 *             #peak_width += 1
 */
  __pyx_slice__19 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__19)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__19);
  __Pyx_GIVEREF(__pyx_slice__19);

  /* "pyquant/cpeaks.pyx":419
 *     peak_range = xdata[-1]-xdata[0]
 *     # initial bound setup
 *     initial_bounds = [(0, 1.01), (xdata[0], xdata[-1]), (min_spacing, peak_range)]             # <<<<<<<<<<<<<<
 *     if bigauss_fit:
 *         initial_bounds.extend([(min_spacing, peak_range)])
 */
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_int_0, __pyx_float_1_01); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 419, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pyquant/cpeaks.pyx":553
 *             res = results[-1]
 *         else:
 *             res = sorted(results, key=attrgetter('fun'))[0]             # <<<<<<<<<<<<<<
 *         n = len(xdata)
 *         k = len(res.x)
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_n_s_fun); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pyquant/cpeaks.pyx":732
 *         else:
 *             peaks, peak_residuals = findAllPeaks(new_x, new_y, min_dist=(new_x[1]-new_x[0])*2.0, peak_width_start=1)
 *             sorted_peaks = sorted([(peaks[i*3:(i+1)*3], get_ppm(start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_slice__24 = PySlice_New(__pyx_int_1, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice__24)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__24);
  __Pyx_GIVEREF(__pyx_slice__24);
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pyquant/cpeaks.pyx":737
 *         if fragment_scan == False and not within_tolerance(sorted_peaks, tolerance):
 *             if calc_start_mz is not None:
 *                 sorted_peaks2 = sorted([(peaks[i*3:(i+1)*3], get_ppm(calc_start_mz+offset, v)) for i,v in enumerate(peaks[1::3])], key=itemgetter(1))             # <<<<<<<<<<<<<<
 *                 if filter(lambda x: x[1]<tolerance, sorted_peaks2):
 *                     sorted_peaks = sorted_peaks2
 */
  __pyx_slice__26 = PySlice_New(__pyx_int_1, Py_None, __pyx_int_3); if (unlikely(!__pyx_slice__26)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__26);
  __Pyx_GIVEREF(__pyx_slice__26);
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "pyquant/cpeaks.pyx":877
 *         # check for contaminant at doubly and triply charged positions to see if we're in another ion's peak
 *         if contaminant_search:
 *             for i in xrange(2, 4):             # <<<<<<<<<<<<<<
 *                 closest_contaminant = find_nearest(non_empty, start-NEUTRON/float(i))
 *                 closest_contaminant_index = find_nearest_index(xdata, closest_contaminant)
 */
  __pyx_tuple__28 = PyTuple_Pack(2, __pyx_int_2, __pyx_int_4); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "pyquant/cpeaks.pyx":883
 *                                          calc_start_mz=start, start_mz=start, isotope=-1, spacing=NEUTRON/float(i),
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:             # <<<<<<<<<<<<<<
 *                     contaminant_int = contaminant_bounds.get('int', 0.)
 * 
 */
  __pyx_tuple__29 = PyTuple_Pack(2, __pyx_n_s_int, __pyx_int_0); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 883, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pyquant/cpeaks.pyx":884
 *                                           quant_method=quant_method, centroid=centroid)
 *                 if contaminant_bounds.get('int', 0) > contaminant_int:
 *                     contaminant_int = contaminant_bounds.get('int', 0.)             # <<<<<<<<<<<<<<
 * 
 *         # set the tolerance for isotopes
 */
  __pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_s_int, __pyx_float_0_); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pyquant/cpeaks.pyx":928
 *     #valid_theor = valid_theor/valid_theor.max()
 *     #best_locations = sorted(looper(selected=valid_vals, df=df, theo=valid_theor), key=itemgetter(0))[0][1]
 *     best_locations = [sorted(valid_locations2[i], key=itemgetter(0))[0] for i in valid_keys]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 928, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "pyquant/cpeaks.pyx":950
 *         micro_dict[isotope_index] = micro_bounds
 *         env_dict[isotope_index] = micro_index
 *         ppm_dict[isotope_index] = micro_bounds.get('error')             # <<<<<<<<<<<<<<
 * 
 *     # in all cases, the envelope is going to be either monotonically decreasing, or a parabola (-x^2)
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_n_s_error); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 950, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__33 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(1, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__34 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(1, 222, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__35 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(1, 259, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__36 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(1, 799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__37 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(1, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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__38 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(1, 823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */
  __pyx_tuple__39 = PyTuple_Pack(31, __pyx_n_s_xdata, __pyx_n_s_ydata, __pyx_n_s_pos, __pyx_n_s_ppm, __pyx_n_s_start_mz, __pyx_n_s_calc_start_mz, __pyx_n_s_isotope, __pyx_n_s_spacing, __pyx_n_s_quant_method, __pyx_n_s_fragment_scan, __pyx_n_s_centroid, __pyx_n_s_tolerance, __pyx_n_s_offset, __pyx_n_s_int_val, __pyx_n_s_peak_mean, __pyx_n_s_df_empty_index, __pyx_n_s_right, __pyx_n_s_left, __pyx_n_s_new_x, __pyx_n_s_new_y, __pyx_n_s_lr, __pyx_n_s_fit, __pyx_n_s_error, __pyx_n_s_peak, __pyx_n_s_peaks, __pyx_n_s_sorted_peaks, __pyx_n_s_peak_residuals, __pyx_n_s_sorted_peaks2, __pyx_n_s_ret_dict, __pyx_n_s_i, __pyx_n_s_v); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);
  __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(11, 0, 31, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_opt_conda_conda_bld_pyquant_ms, __pyx_n_s_findMicro, 690, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 690, __pyx_L1_error)

  /* "pyquant/cpeaks.pyx":755
 *     return ret_dict
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     return array[find_nearest_index(array, value)]
 * 
 */
  __pyx_tuple__41 = PyTuple_Pack(2, __pyx_n_s_array, __pyx_n_s_value); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);
  __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_opt_conda_conda_bld_pyquant_ms, __pyx_n_s_find_nearest, 755, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 755, __pyx_L1_error)

  /* "pyquant/cpeaks.pyx":758
 *     return array[find_nearest_index(array, value)]
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:
 */
  __pyx_tuple__43 = PyTuple_Pack(3, __pyx_n_s_array, __pyx_n_s_value, __pyx_n_s_idx); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);
  __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_opt_conda_conda_bld_pyquant_ms, __pyx_n_s_find_nearest_index, 758, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 758, __pyx_L1_error)

  /* "pyquant/cpeaks.pyx":769
 *         return idx
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 */
  __pyx_tuple__45 = PyTuple_Pack(7, __pyx_n_s_array, __pyx_n_s_value, __pyx_n_s_indices, __pyx_n_s_out, __pyx_n_s_search_index, __pyx_n_s_idx, __pyx_n_s_search_value); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);
  __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_opt_conda_conda_bld_pyquant_ms, __pyx_n_s_find_nearest_indices, 769, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_0_ = PyFloat_FromDouble(0.); if (unlikely(!__pyx_float_0_)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_0 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_float_0_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_1 = PyFloat_FromDouble(0.1); if (unlikely(!__pyx_float_0_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_9 = PyFloat_FromDouble(0.9); if (unlikely(!__pyx_float_0_9)) __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_2_5 = PyFloat_FromDouble(2.5); if (unlikely(!__pyx_float_2_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_05 = PyFloat_FromDouble(0.05); if (unlikely(!__pyx_float_0_05)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1_01 = PyFloat_FromDouble(1.01); if (unlikely(!__pyx_float_1_01)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1eneg_20 = PyFloat_FromDouble(1e-20); if (unlikely(!__pyx_float_1eneg_20)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1000000_0 = PyFloat_FromDouble(1000000.0); if (unlikely(!__pyx_float_1000000_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_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __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_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_12 = PyInt_FromLong(12); if (unlikely(!__pyx_int_12)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_14 = PyInt_FromLong(14); if (unlikely(!__pyx_int_14)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_2 = PyInt_FromLong(-2); if (unlikely(!__pyx_int_neg_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcpeaks(void); /*proto*/
PyMODINIT_FUNC initcpeaks(void)
#else
PyMODINIT_FUNC PyInit_cpeaks(void); /*proto*/
PyMODINIT_FUNC PyInit_cpeaks(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_cpeaks(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("cpeaks", __pyx_methods, 0, 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_pyquant__cpeaks) {
    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, "pyquant.cpeaks")) {
      if (unlikely(PyDict_SetItemString(modules, "pyquant.cpeaks", __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 ---*/
  if (PyType_Ready(&__pyx_type_7pyquant_6cpeaks___pyx_scope_struct__findMicro) < 0) __PYX_ERR(0, 690, __pyx_L1_error)
  __pyx_type_7pyquant_6cpeaks___pyx_scope_struct__findMicro.tp_print = 0;
  __pyx_ptype_7pyquant_6cpeaks___pyx_scope_struct__findMicro = &__pyx_type_7pyquant_6cpeaks___pyx_scope_struct__findMicro;
  /*--- 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)
  /*--- 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

  /* "pyquant/cpeaks.pyx":1
 * import numpy as np             # <<<<<<<<<<<<<<
 * import sys
 * from copy import deepcopy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); 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_np, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":2
 * import numpy as np
 * import sys             # <<<<<<<<<<<<<<
 * from copy import deepcopy
 * cimport numpy as np
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":3
 * import numpy as np
 * import sys
 * from copy import deepcopy             # <<<<<<<<<<<<<<
 * cimport numpy as np
 * cimport cython
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_deepcopy);
  __Pyx_GIVEREF(__pyx_n_s_deepcopy);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_deepcopy);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_copy, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __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_deepcopy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_deepcopy, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":7
 * cimport cython
 * ctypedef np.float_t FLOAT_t
 * from scipy import optimize, integrate             # <<<<<<<<<<<<<<
 * from scipy.interpolate import interp1d
 * from scipy.ndimage.filters import gaussian_filter1d
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_optimize);
  __Pyx_GIVEREF(__pyx_n_s_optimize);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_optimize);
  __Pyx_INCREF(__pyx_n_s_integrate);
  __Pyx_GIVEREF(__pyx_n_s_integrate);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_integrate);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_scipy, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __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_optimize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_optimize, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_integrate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_integrate, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":8
 * ctypedef np.float_t FLOAT_t
 * from scipy import optimize, integrate
 * from scipy.interpolate import interp1d             # <<<<<<<<<<<<<<
 * from scipy.ndimage.filters import gaussian_filter1d
 * from scipy.signal import argrelmax, argrelmin, convolve, kaiser
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_interp1d);
  __Pyx_GIVEREF(__pyx_n_s_interp1d);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_interp1d);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_interpolate, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __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_interp1d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_interp1d, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":9
 * from scipy import optimize, integrate
 * from scipy.interpolate import interp1d
 * from scipy.ndimage.filters import gaussian_filter1d             # <<<<<<<<<<<<<<
 * from scipy.signal import argrelmax, argrelmin, convolve, kaiser
 * from operator import itemgetter, attrgetter
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_gaussian_filter1d);
  __Pyx_GIVEREF(__pyx_n_s_gaussian_filter1d);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_gaussian_filter1d);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_scipy_ndimage_filters, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __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_gaussian_filter1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_gaussian_filter1d, __pyx_t_2) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":10
 * from scipy.interpolate import interp1d
 * from scipy.ndimage.filters import gaussian_filter1d
 * from scipy.signal import argrelmax, argrelmin, convolve, kaiser             # <<<<<<<<<<<<<<
 * from operator import itemgetter, attrgetter
 * from collections import OrderedDict
 */
  __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_argrelmax);
  __Pyx_GIVEREF(__pyx_n_s_argrelmax);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_argrelmax);
  __Pyx_INCREF(__pyx_n_s_argrelmin);
  __Pyx_GIVEREF(__pyx_n_s_argrelmin);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_argrelmin);
  __Pyx_INCREF(__pyx_n_s_convolve);
  __Pyx_GIVEREF(__pyx_n_s_convolve);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_convolve);
  __Pyx_INCREF(__pyx_n_s_kaiser);
  __Pyx_GIVEREF(__pyx_n_s_kaiser);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_kaiser);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_signal, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __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_argrelmax); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_argrelmax, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_argrelmin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_argrelmin, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_convolve); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_convolve, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_kaiser); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_kaiser, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":11
 * from scipy.ndimage.filters import gaussian_filter1d
 * from scipy.signal import argrelmax, argrelmin, convolve, kaiser
 * from operator import itemgetter, attrgetter             # <<<<<<<<<<<<<<
 * from collections import OrderedDict
 * from pythomics.proteomics.config import NEUTRON
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_itemgetter);
  __Pyx_GIVEREF(__pyx_n_s_itemgetter);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_itemgetter);
  __Pyx_INCREF(__pyx_n_s_attrgetter);
  __Pyx_GIVEREF(__pyx_n_s_attrgetter);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_attrgetter);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_operator, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __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_itemgetter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itemgetter, __pyx_t_2) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_attrgetter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_attrgetter, __pyx_t_2) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":12
 * from scipy.signal import argrelmax, argrelmin, convolve, kaiser
 * from operator import itemgetter, attrgetter
 * from collections import OrderedDict             # <<<<<<<<<<<<<<
 * from pythomics.proteomics.config import NEUTRON
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_OrderedDict);
  __Pyx_GIVEREF(__pyx_n_s_OrderedDict);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_OrderedDict);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __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_OrderedDict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_OrderedDict, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pyquant/cpeaks.pyx":13
 * from operator import itemgetter, attrgetter
 * from collections import OrderedDict
 * from pythomics.proteomics.config import NEUTRON             # <<<<<<<<<<<<<<
 * 
 * cdef int within_bounds(np.ndarray[FLOAT_t, ndim=1] res, np.ndarray[FLOAT_t, ndim=2] bnds):
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_NEUTRON);
  __Pyx_GIVEREF(__pyx_n_s_NEUTRON);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_NEUTRON);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_pythomics_proteomics_config, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __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_NEUTRON); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NEUTRON, __pyx_t_2) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":690
 *     return 0
 * 
 * def findMicro(np.ndarray[FLOAT_t, ndim=1] xdata, np.ndarray[FLOAT_t, ndim=1] ydata, pos, ppm=None,             # <<<<<<<<<<<<<<
 *               start_mz=None, calc_start_mz=None, isotope=0, spacing=0, quant_method='integrate', fragment_scan=False,
 *                centroid=False):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7pyquant_6cpeaks_23findMicro, NULL, __pyx_n_s_pyquant_cpeaks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_findMicro, __pyx_t_1) < 0) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":755
 *     return ret_dict
 * 
 * def find_nearest(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     return array[find_nearest_index(array, value)]
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7pyquant_6cpeaks_25find_nearest, NULL, __pyx_n_s_pyquant_cpeaks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_find_nearest, __pyx_t_1) < 0) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":758
 *     return array[find_nearest_index(array, value)]
 * 
 * def find_nearest_index(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     idx = np.searchsorted(array, value, side="left")
 *     if idx == 0:
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7pyquant_6cpeaks_27find_nearest_index, NULL, __pyx_n_s_pyquant_cpeaks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_find_nearest_index, __pyx_t_1) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":769
 *         return idx
 * 
 * def find_nearest_indices(np.ndarray[FLOAT_t, ndim=1] array, value):             # <<<<<<<<<<<<<<
 *     indices = np.searchsorted(array, value, side="left")
 *     out = []
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7pyquant_6cpeaks_29find_nearest_indices, NULL, __pyx_n_s_pyquant_cpeaks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_find_nearest_indices, __pyx_t_1) < 0) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pyquant/cpeaks.pyx":1
 * import numpy as np             # <<<<<<<<<<<<<<
 * import sys
 * from copy import deepcopy
 */
  __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;

  /* "../../_b_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/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
 */

  /*--- 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 pyquant.cpeaks", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pyquant.cpeaks");
  }
  __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;
}

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

/* PyObjectCall */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* RaiseTooManyValuesToUnpack */
  static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
  static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
  static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

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

/* 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_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        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));
}

/* PyErrFetchRestore */
  #if CYTHON_COMPILING_IN_CPYTHON
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
}

/* GetModuleGlobalName */
  static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    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;
}

/* 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) {
#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);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* ExtTypeTest */
      static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(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;
}

/* BufferFallbackError */
      static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

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

/* None */
      static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

/* BufferIndexError */
      static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

/* PyObjectCallNoArg */
      #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#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

/* PyIntBinop */
        #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) {
            Py_RETURN_TRUE;
        } else {
            Py_RETURN_FALSE;
        }
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                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;
                    }
                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;
                    }
                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;
                    }
                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;
                    }
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            if ((double)a == (double)b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif

/* PyIntBinop */
        #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = a % b;
            x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        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;
                    } 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;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                default: return PyLong_Type.tp_as_number->nb_remainder(op1, op2);
            }
        }
                x = a % b;
                x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla % llb;
                llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    return (inplace ? PyNumber_InPlaceRemainder : PyNumber_Remainder)(op1, op2);
}
#endif

/* PyIntBinop */
        #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        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;
                    } 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;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* RaiseNoneIterError */
        static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* SliceObject */
        static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* 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 bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            args = PyTuple_New(2);
            if (unlikely(!args)) goto bad;
            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);
bad:
    Py_XDECREF(method);
    return result;
}

/* pop_index */
        static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) {
    PyObject *r;
    if (unlikely(!py_ix)) return NULL;
    r = __Pyx__PyObject_PopIndex(L, py_ix);
    Py_DECREF(py_ix);
    return r;
}
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) {
    return __Pyx_PyObject_CallMethod1(L, __pyx_n_s_pop, py_ix);
}
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) {
    Py_ssize_t size = PyList_GET_SIZE(L);
    if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
        Py_ssize_t cix = ix;
        if (cix < 0) {
            cix += size;
        }
        if (likely(0 <= cix && cix < size)) {
            PyObject* v = PyList_GET_ITEM(L, cix);
            Py_SIZE(L) -= 1;
            size -= 1;
            memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
            return v;
        }
    }
    if (py_ix == Py_None) {
        return __Pyx__PyObject_PopNewIndex(L, PyInt_FromSsize_t(ix));
    } else {
        return __Pyx__PyObject_PopIndex(L, py_ix);
    }
}
#endif

/* SaveResetException */
        #if CYTHON_COMPILING_IN_CPYTHON
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_COMPILING_IN_CPYTHON
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_COMPILING_IN_CPYTHON
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_COMPILING_IN_CPYTHON
    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_COMPILING_IN_CPYTHON
    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_COMPILING_IN_CPYTHON
    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;
}

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

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

/* PyFloatBinop */
            #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyFloat_AddObjC(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 && PY_MAJOR_VERSION >= 3
        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 ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
    }
        PyFPE_START_PROTECT("add", return NULL)
        result = a + b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* UnpackUnboundCMethod */
              static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(PyObject_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_O | METH_NOARGS);
    }
#endif
    return 0;
}

/* CallUnboundCMethod0 */
              static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

/* py_dict_items */
              static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d);
    else
        return PyDict_Items(d);
}

/* PyIntBinop */
              #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        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;
                    } 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;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* PyIntBinop */
              #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        const long a = intval;
        long x;
        long b = PyInt_AS_LONG(op2);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op2))) {
        const long a = intval;
        long b, x;
        const PY_LONG_LONG lla = intval;
        PY_LONG_LONG llb, llx;
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            b = likely(size) ? digits[0] : 0;
            if (size == -1) b = -b;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = -(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;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = (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;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = -(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;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = (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;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op2)) {
        const long a = intval;
        double b = PyFloat_AS_DOUBLE(op2);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* GetAttr */
              static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_COMPILING_IN_CPYTHON
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* GetAttr3 */
              static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError))
            goto bad;
        PyErr_Clear();
        r = d;
        Py_INCREF(d);
    }
    return r;
bad:
    return NULL;
}

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

/* FetchCommonType */
              static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

/* CythonFunction */
              static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp = op->func_doc;
    if (value == NULL) {
        value = Py_None;
    }
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
    PyObject *self;
    self = m->func_closure;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
{
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    int result = 0;
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    #if CYTHON_COMPILING_IN_CPYTHON
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    #else
    op->defaults_tuple = PySequence_ITEM(res, 0);
    if (unlikely(!op->defaults_tuple)) result = -1;
    else {
        op->defaults_kwdict = PySequence_ITEM(res, 1);
        if (unlikely(!op->defaults_kwdict)) result = -1;
    }
    #endif
    Py_DECREF(res);
    return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_CyFunction_members[] = {
    {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromString(m->func.m_ml->ml_name);
#else
    return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
    if (op == NULL)
        return NULL;
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = NULL;
    op->func.m_ml = ml;
    op->func.m_self = (PyObject *) op;
    Py_XINCREF(closure);
    op->func_closure = closure;
    Py_XINCREF(module);
    op->func.m_module = module;
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    PyObject_GC_Track(op);
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
    Py_CLEAR(m->func.m_module);
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyObject_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    if (__Pyx_CyFunction_weakreflist(m) != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    PyObject_GC_Del(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
    Py_VISIT(m->func.m_module);
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
        Py_INCREF(func);
        return func;
    }
    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
        if (type == NULL)
            type = (PyObject *)(Py_TYPE(obj));
        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
    return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
#if CYTHON_COMPILING_IN_PYPY
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = f->m_ml->ml_meth;
    PyObject *self = f->m_self;
    Py_ssize_t size;
    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
    case METH_VARARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0))
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 0))
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 1)) {
                PyObject *result, *arg0 = PySequence_ITEM(arg, 0);
                if (unlikely(!arg0)) return NULL;
                result = (*meth)(self, arg0);
                Py_DECREF(arg0);
                return result;
            }
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
                        "longer supported!");
        return NULL;
    }
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
    return NULL;
}
#else
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
	return PyCFunction_Call(func, arg, kw);
}
#endif
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_Call,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_CyFunction_descr_get,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
};
static int __pyx_CyFunction_init(void) {
#if !CYTHON_COMPILING_IN_PYPY
    __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
#endif
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (__pyx_CyFunctionType == NULL) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyObject_Malloc(size);
    if (!m->defaults)
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

/* PyFloatBinop */
                  #if CYTHON_COMPILING_IN_CPYTHON
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 && PY_MAJOR_VERSION >= 3
        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

/* SliceTupleAndList */
                    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
    Py_ssize_t start = *_start, stop = *_stop, length = *_length;
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    *_length = stop - start;
    *_start = start;
    *_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyList_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyList_New(0);
    dest = PyList_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyListObject*)src)->ob_item + start,
        ((PyListObject*)dest)->ob_item,
        length);
    return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyTuple_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyTuple_New(0);
    dest = PyTuple_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyTupleObject*)src)->ob_item + start,
        ((PyTupleObject*)dest)->ob_item,
        length);
    return dest;
}
#endif

/* RaiseException */
                    #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if 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

/* 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;
    py_frame->f_lineno = 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_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);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        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_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);
        } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(Py_intptr_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(Py_intptr_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        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);
    }
}

/* 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_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);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

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

/* None */
                      #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        float denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(a, a);
                    case 3:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, a);
                    case 4:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_absf(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

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

/* None */
                      #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(a, a);
                    case 3:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, a);
                    case 4:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

/* 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);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(enum NPY_TYPES) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum NPY_TYPES),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
                      static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } 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))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
                      static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } 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))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#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;
}

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

/* 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) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.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 */
