/* Generated by Cython 0.12.1 on Mon May 31 10:16:35 2010 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyUnicode_Type
  #define PyString_CheckExact          PyUnicode_CheckExact
#else
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_CheckExact           PyString_CheckExact
#endif

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

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__scipy__special__lambertw
#include "math.h"
#include "numpy/npy_math.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #else
    #define CYTHON_INLINE 
  #endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBytes_FromUString(s)      __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)        ((unsigned char*) __Pyx_PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif


#if !defined(T_ULONGLONG)
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : -1))))
#else
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : \
        ((sizeof(x) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))))
#endif
#if !defined(T_LONGLONG)
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : -1))))
#else
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : \
        ((sizeof(x) == sizeof(PY_LONG_LONG))   ? T_LONGLONG : -1)))))
#endif

#define __Pyx_T_FLOATING(x) \
        ((sizeof(x) == sizeof(float)) ? T_FLOAT : \
        ((sizeof(x) == sizeof(double)) ? T_DOUBLE : -1))

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

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


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


#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

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

#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) {
    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;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #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_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #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_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

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

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

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*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(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq(a, b)   ((a)==(b))
    #define __Pyx_c_sum(a, b)  ((a)+(b))
    #define __Pyx_c_diff(a, b) ((a)-(b))
    #define __Pyx_c_prod(a, b) ((a)*(b))
    #define __Pyx_c_quot(a, b) ((a)/(b))
    #define __Pyx_c_neg(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero(z) ((z)==(double)0)
    #define __Pyx_c_conj(z)    (::std::conj(z))
    /*#define __Pyx_c_abs(z)     (::std::abs(z))*/
  #else
    #define __Pyx_c_is_zero(z) ((z)==0)
    #define __Pyx_c_conj(z)    (conj(z))
    /*#define __Pyx_c_abs(z)     (cabs(z))*/
 #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);
    /*static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);*/
#endif

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

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

#define __pyx_PyComplex_FromComplex(z) \
        PyComplex_FromDoubles((double)__Pyx_CREAL(z), \
                              (double)__Pyx_CIMAG(z))

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp);

static CYTHON_INLINE npy_intp __Pyx_PyInt_from_py_npy_intp(PyObject *);

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

#ifndef __PYX_FORCE_INIT_THREADS
  #if PY_VERSION_HEX < 0x02040200
    #define __PYX_FORCE_INIT_THREADS 1
  #else
    #define __PYX_FORCE_INIT_THREADS 0
  #endif
#endif

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

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

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from cython */

/* Module declarations from scipy.special.lambertw */

static PyUFuncGenericFunction __pyx_v_5scipy_7special_8lambertw__loop_funcs[1];
static char __pyx_v_5scipy_7special_8lambertw__inp_outp_types[4];
static void *__pyx_v_5scipy_7special_8lambertw_the_func_to_apply[1];
static CYTHON_INLINE int __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE double __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_t_double_complex); /*proto*/
static void __pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_t_double_complex); /*proto*/
static __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_lambertw_scalar(__pyx_t_double_complex, long, double); /*proto*/
static void __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec(char **, npy_intp *, npy_intp *, void *); /*proto*/
#define __Pyx_MODULE_NAME "scipy.special.lambertw"
int __pyx_module_is_main_scipy__special__lambertw = 0;

/* Implementation of scipy.special.lambertw */
static PyObject *__pyx_builtin_range;
static char __pyx_k_1[] = "Lambert W iteration failed to converge: %r";
static char __pyx_k_3[] = "";
static char __pyx_k_4[] = "lambertw (line 193)";
static char __pyx_k__k[] = "k";
static char __pyx_k__z[] = "z";
static char __pyx_k__tol[] = "tol";
static char __pyx_k__imag[] = "imag";
static char __pyx_k__real[] = "real";
static char __pyx_k__warn[] = "warn";
static char __pyx_k__range[] = "range";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__lambertw[] = "lambertw";
static char __pyx_k__warnings[] = "warnings";
static char __pyx_k___lambertw[] = "_lambertw";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_u_4;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___lambertw;
static PyObject *__pyx_n_s__imag;
static PyObject *__pyx_n_s__k;
static PyObject *__pyx_n_s__lambertw;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__real;
static PyObject *__pyx_n_s__tol;
static PyObject *__pyx_n_s__warn;
static PyObject *__pyx_n_s__warnings;
static PyObject *__pyx_n_s__z;
static PyObject *__pyx_int_0;
static PyObject *__pyx_k_2;

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":44
 *     double NPY_PI
 * 
 * cdef inline bint zisnan(double complex x) nogil:             # <<<<<<<<<<<<<<
 *     return npy_isnan(x.real) or npy_isnan(x.imag)
 * 
 */

static CYTHON_INLINE int __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_t_double_complex __pyx_v_x) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":45
 * 
 * cdef inline bint zisnan(double complex x) nogil:
 *     return npy_isnan(x.real) or npy_isnan(x.imag)             # <<<<<<<<<<<<<<
 * 
 * cdef inline double zabs(double complex x) nogil:
 */
  __pyx_t_1 = npy_isnan(__Pyx_CREAL(__pyx_v_x));
  if (!__pyx_t_1) {
    __pyx_t_2 = npy_isnan(__Pyx_CIMAG(__pyx_v_x));
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  __pyx_r = __pyx_t_3;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":47
 *     return npy_isnan(x.real) or npy_isnan(x.imag)
 * 
 * cdef inline double zabs(double complex x) nogil:             # <<<<<<<<<<<<<<
 *     cdef double r
 *     r = npy_cabs((<npy_cdouble*>&x)[0])
 */

static CYTHON_INLINE double __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_t_double_complex __pyx_v_x) {
  double __pyx_v_r;
  double __pyx_r;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":49
 * cdef inline double zabs(double complex x) nogil:
 *     cdef double r
 *     r = npy_cabs((<npy_cdouble*>&x)[0])             # <<<<<<<<<<<<<<
 *     return r
 * 
 */
  __pyx_v_r = npy_cabs((((npy_cdouble *)(&__pyx_v_x))[0]));

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":50
 *     cdef double r
 *     r = npy_cabs((<npy_cdouble*>&x)[0])
 *     return r             # <<<<<<<<<<<<<<
 * 
 * cdef inline double complex zlog(double complex x) nogil:
 */
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":52
 *     return r
 * 
 * cdef inline double complex zlog(double complex x) nogil:             # <<<<<<<<<<<<<<
 *     cdef npy_cdouble r
 *     r = npy_clog((<npy_cdouble*>&x)[0])
 */

static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_t_double_complex __pyx_v_x) {
  npy_cdouble __pyx_v_r;
  __pyx_t_double_complex __pyx_r;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":54
 * cdef inline double complex zlog(double complex x) nogil:
 *     cdef npy_cdouble r
 *     r = npy_clog((<npy_cdouble*>&x)[0])             # <<<<<<<<<<<<<<
 *     return (<double complex*>&r)[0]
 * 
 */
  __pyx_v_r = npy_clog((((npy_cdouble *)(&__pyx_v_x))[0]));

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":55
 *     cdef npy_cdouble r
 *     r = npy_clog((<npy_cdouble*>&x)[0])
 *     return (<double complex*>&r)[0]             # <<<<<<<<<<<<<<
 * 
 * cdef inline double complex zexp(double complex x) nogil:
 */
  __pyx_r = (((__pyx_t_double_complex *)(&__pyx_v_r))[0]);
  goto __pyx_L0;

  __pyx_r = __pyx_t_double_complex_from_parts(0, 0);
  __pyx_L0:;
  return __pyx_r;
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":57
 *     return (<double complex*>&r)[0]
 * 
 * cdef inline double complex zexp(double complex x) nogil:             # <<<<<<<<<<<<<<
 *     cdef npy_cdouble r
 *     r = npy_cexp((<npy_cdouble*>&x)[0])
 */

static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_t_double_complex __pyx_v_x) {
  npy_cdouble __pyx_v_r;
  __pyx_t_double_complex __pyx_r;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":59
 * cdef inline double complex zexp(double complex x) nogil:
 *     cdef npy_cdouble r
 *     r = npy_cexp((<npy_cdouble*>&x)[0])             # <<<<<<<<<<<<<<
 *     return (<double complex*>&r)[0]
 * 
 */
  __pyx_v_r = npy_cexp((((npy_cdouble *)(&__pyx_v_x))[0]));

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":60
 *     cdef npy_cdouble r
 *     r = npy_cexp((<npy_cdouble*>&x)[0])
 *     return (<double complex*>&r)[0]             # <<<<<<<<<<<<<<
 * 
 * cdef void lambertw_raise_warning(double complex z) with gil:
 */
  __pyx_r = (((__pyx_t_double_complex *)(&__pyx_v_r))[0]);
  goto __pyx_L0;

  __pyx_r = __pyx_t_double_complex_from_parts(0, 0);
  __pyx_L0:;
  return __pyx_r;
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":62
 *     return (<double complex*>&r)[0]
 * 
 * cdef void lambertw_raise_warning(double complex z) with gil:             # <<<<<<<<<<<<<<
 *     warnings.warn("Lambert W iteration failed to converge: %r" % z)
 * 
 */

static  void __pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_t_double_complex __pyx_v_z) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("lambertw_raise_warning");

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":63
 * 
 * cdef void lambertw_raise_warning(double complex z) with gil:
 *     warnings.warn("Lambert W iteration failed to converge: %r" % z)             # <<<<<<<<<<<<<<
 * 
 * # Heavy lifting is here:
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__warnings); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __pyx_PyComplex_FromComplex(__pyx_v_z); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_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;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("scipy.special.lambertw.lambertw_raise_warning");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":68
 * 
 * @cython.cdivision(True)
 * cdef double complex lambertw_scalar(double complex z, long k, double tol) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     This is just the implementation of W for a single input z.
 */

static  __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_lambertw_scalar(__pyx_t_double_complex __pyx_v_z, long __pyx_v_k, double __pyx_v_tol) {
  __pyx_t_double_complex __pyx_v_w;
  double __pyx_v_u;
  double __pyx_v_absz;
  __pyx_t_double_complex __pyx_v_ew;
  __pyx_t_double_complex __pyx_v_wew;
  __pyx_t_double_complex __pyx_v_wewz;
  __pyx_t_double_complex __pyx_v_wn;
  int __pyx_v_i;
  __pyx_t_double_complex __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  int __pyx_t_6;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":74
 *     """
 *     # Comments copied verbatim from [2] are marked with '>'
 *     if zisnan(z):             # <<<<<<<<<<<<<<
 *         return z
 * 
 */
  __pyx_t_1 = __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_v_z);
  if (__pyx_t_1) {

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":75
 *     # Comments copied verbatim from [2] are marked with '>'
 *     if zisnan(z):
 *         return z             # <<<<<<<<<<<<<<
 * 
 *     # Return value:
 */
    __pyx_r = __pyx_v_z;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":82
 *     #> We must be extremely careful near the singularities at -1/e and 0
 *     cdef double u
 *     u = exp(-1)             # <<<<<<<<<<<<<<
 * 
 *     cdef double absz
 */
  __pyx_v_u = exp(-1);

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":85
 * 
 *     cdef double absz
 *     absz = zabs(z)             # <<<<<<<<<<<<<<
 *     if absz <= u:
 *         if z == 0:
 */
  __pyx_v_absz = __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_z);

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":86
 *     cdef double absz
 *     absz = zabs(z)
 *     if absz <= u:             # <<<<<<<<<<<<<<
 *         if z == 0:
 *             #> w(0,0) = 0; for all other branches we hit the pole
 */
  __pyx_t_1 = (__pyx_v_absz <= __pyx_v_u);
  if (__pyx_t_1) {

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":87
 *     absz = zabs(z)
 *     if absz <= u:
 *         if z == 0:             # <<<<<<<<<<<<<<
 *             #> w(0,0) = 0; for all other branches we hit the pole
 *             if k == 0:
 */
    __pyx_t_1 = (__Pyx_c_eq(__pyx_v_z, __pyx_t_double_complex_from_parts(0, 0)));
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":89
 *         if z == 0:
 *             #> w(0,0) = 0; for all other branches we hit the pole
 *             if k == 0:             # <<<<<<<<<<<<<<
 *                 return z
 *             return -NPY_INFINITY
 */
      __pyx_t_1 = (__pyx_v_k == 0);
      if (__pyx_t_1) {

        /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":90
 *             #> w(0,0) = 0; for all other branches we hit the pole
 *             if k == 0:
 *                 return z             # <<<<<<<<<<<<<<
 *             return -NPY_INFINITY
 * 
 */
        __pyx_r = __pyx_v_z;
        goto __pyx_L0;
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":91
 *             if k == 0:
 *                 return z
 *             return -NPY_INFINITY             # <<<<<<<<<<<<<<
 * 
 *         if k == 0:
 */
      __pyx_r = __pyx_t_double_complex_from_parts((-NPY_INFINITY), 0);
      goto __pyx_L0;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":93
 *             return -NPY_INFINITY
 * 
 *         if k == 0:             # <<<<<<<<<<<<<<
 *             w = z # Initial guess for iteration
 *         #> For small real z < 0, the -1 branch beaves roughly like log(-z)
 */
    __pyx_t_1 = (__pyx_v_k == 0);
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":94
 * 
 *         if k == 0:
 *             w = z # Initial guess for iteration             # <<<<<<<<<<<<<<
 *         #> For small real z < 0, the -1 branch beaves roughly like log(-z)
 *         elif k == -1 and z.imag ==0 and z.real < 0:
 */
      __pyx_v_w = __pyx_v_z;
      goto __pyx_L7;
    }

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":96
 *             w = z # Initial guess for iteration
 *         #> For small real z < 0, the -1 branch beaves roughly like log(-z)
 *         elif k == -1 and z.imag ==0 and z.real < 0:             # <<<<<<<<<<<<<<
 *             w = log(-z.real)
 *         #> Use a simple asymptotic approximation.
 */
    __pyx_t_1 = (__pyx_v_k == -1);
    if (__pyx_t_1) {
      __pyx_t_2 = (__Pyx_CIMAG(__pyx_v_z) == 0);
      if (__pyx_t_2) {
        __pyx_t_3 = (__Pyx_CREAL(__pyx_v_z) < 0);
        __pyx_t_4 = __pyx_t_3;
      } else {
        __pyx_t_4 = __pyx_t_2;
      }
      __pyx_t_2 = __pyx_t_4;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (__pyx_t_2) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":97
 *         #> For small real z < 0, the -1 branch beaves roughly like log(-z)
 *         elif k == -1 and z.imag ==0 and z.real < 0:
 *             w = log(-z.real)             # <<<<<<<<<<<<<<
 *         #> Use a simple asymptotic approximation.
 *         else:
 */
      __pyx_v_w = __pyx_t_double_complex_from_parts(log((-__Pyx_CREAL(__pyx_v_z))), 0);
      goto __pyx_L7;
    }
    /*else*/ {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":100
 *         #> Use a simple asymptotic approximation.
 *         else:
 *             w = zlog(z)             # <<<<<<<<<<<<<<
 *             #> The branches are roughly logarithmic. This approximation
 *             #> gets better for large |k|; need to check that this always
 */
      __pyx_v_w = __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_v_z);

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":104
 *             #> gets better for large |k|; need to check that this always
 *             #> works for k ~= -1, 0, 1.
 *             if k: w = w + k*2*NPY_PI*1j             # <<<<<<<<<<<<<<
 * 
 *     elif k == 0 and z.imag and zabs(z) <= 0.7:
 */
      __pyx_t_5 = __pyx_v_k;
      if (__pyx_t_5) {
        __pyx_v_w = __Pyx_c_sum(__pyx_v_w, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((__pyx_v_k * 2) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
        goto __pyx_L8;
      }
      __pyx_L8:;
    }
    __pyx_L7:;
    goto __pyx_L4;
  }

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":106
 *             if k: w = w + k*2*NPY_PI*1j
 * 
 *     elif k == 0 and z.imag and zabs(z) <= 0.7:             # <<<<<<<<<<<<<<
 *         #> Both the W(z) ~= z and W(z) ~= ln(z) approximations break
 *         #> down around z ~= -0.5 (converging to the wrong branch), so patch
 */
  __pyx_t_2 = (__pyx_v_k == 0);
  if (__pyx_t_2) {
    if ((__Pyx_CIMAG(__pyx_v_z) != 0)) {
      __pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_z) <= 0.69999999999999996);
      __pyx_t_4 = __pyx_t_1;
    } else {
      __pyx_t_4 = (__Pyx_CIMAG(__pyx_v_z) != 0);
    }
    __pyx_t_1 = __pyx_t_4;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":110
 *         #> down around z ~= -0.5 (converging to the wrong branch), so patch
 *         #> with a constant approximation (adjusted for sign)
 *         if zabs(z+0.5) < 0.1:             # <<<<<<<<<<<<<<
 *             if z.imag > 0:
 *                 w = 0.7 + 0.7j
 */
    __pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__Pyx_c_sum(__pyx_v_z, __pyx_t_double_complex_from_parts(0.5, 0))) < 0.10000000000000001);
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":111
 *         #> with a constant approximation (adjusted for sign)
 *         if zabs(z+0.5) < 0.1:
 *             if z.imag > 0:             # <<<<<<<<<<<<<<
 *                 w = 0.7 + 0.7j
 *             else:
 */
      __pyx_t_1 = (__Pyx_CIMAG(__pyx_v_z) > 0);
      if (__pyx_t_1) {

        /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":112
 *         if zabs(z+0.5) < 0.1:
 *             if z.imag > 0:
 *                 w = 0.7 + 0.7j             # <<<<<<<<<<<<<<
 *             else:
 *                 w = 0.7 - 0.7j
 */
        __pyx_v_w = __Pyx_c_sum(__pyx_t_double_complex_from_parts(0.69999999999999996, 0), __pyx_t_double_complex_from_parts(0, 0.69999999999999996));
        goto __pyx_L10;
      }
      /*else*/ {

        /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":114
 *                 w = 0.7 + 0.7j
 *             else:
 *                 w = 0.7 - 0.7j             # <<<<<<<<<<<<<<
 *         else:
 *             w = z
 */
        __pyx_v_w = __Pyx_c_diff(__pyx_t_double_complex_from_parts(0.69999999999999996, 0), __pyx_t_double_complex_from_parts(0, 0.69999999999999996));
      }
      __pyx_L10:;
      goto __pyx_L9;
    }
    /*else*/ {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":116
 *                 w = 0.7 - 0.7j
 *         else:
 *             w = z             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
      __pyx_v_w = __pyx_v_z;
    }
    __pyx_L9:;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":119
 * 
 *     else:
 *         if z.real == NPY_INFINITY:             # <<<<<<<<<<<<<<
 *             if k == 0:
 *                 return z
 */
    __pyx_t_1 = (__Pyx_CREAL(__pyx_v_z) == NPY_INFINITY);
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":120
 *     else:
 *         if z.real == NPY_INFINITY:
 *             if k == 0:             # <<<<<<<<<<<<<<
 *                 return z
 *             else:
 */
      __pyx_t_1 = (__pyx_v_k == 0);
      if (__pyx_t_1) {

        /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":121
 *         if z.real == NPY_INFINITY:
 *             if k == 0:
 *                 return z             # <<<<<<<<<<<<<<
 *             else:
 *                 return z + 2*k*NPY_PI*1j
 */
        __pyx_r = __pyx_v_z;
        goto __pyx_L0;
        goto __pyx_L12;
      }
      /*else*/ {

        /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":123
 *                 return z
 *             else:
 *                 return z + 2*k*NPY_PI*1j             # <<<<<<<<<<<<<<
 * 
 *         if z.real == -NPY_INFINITY:
 */
        __pyx_r = __Pyx_c_sum(__pyx_v_z, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((2 * __pyx_v_k) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
        goto __pyx_L0;
      }
      __pyx_L12:;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":125
 *                 return z + 2*k*NPY_PI*1j
 * 
 *         if z.real == -NPY_INFINITY:             # <<<<<<<<<<<<<<
 *             return (-z) + (2*k+1)*NPY_PI*1j
 * 
 */
    __pyx_t_1 = (__Pyx_CREAL(__pyx_v_z) == (-NPY_INFINITY));
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":126
 * 
 *         if z.real == -NPY_INFINITY:
 *             return (-z) + (2*k+1)*NPY_PI*1j             # <<<<<<<<<<<<<<
 * 
 *         #> Simple asymptotic approximation as above
 */
      __pyx_r = __Pyx_c_sum(__Pyx_c_neg(__pyx_v_z), __Pyx_c_prod(__pyx_t_double_complex_from_parts((((2 * __pyx_v_k) + 1) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
      goto __pyx_L0;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":129
 * 
 *         #> Simple asymptotic approximation as above
 *         w = zlog(z)             # <<<<<<<<<<<<<<
 *         if k: w = w + k*2*NPY_PI*1j
 * 
 */
    __pyx_v_w = __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_v_z);

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":130
 *         #> Simple asymptotic approximation as above
 *         w = zlog(z)
 *         if k: w = w + k*2*NPY_PI*1j             # <<<<<<<<<<<<<<
 * 
 *     #> Use Halley iteration to solve w*exp(w) = z
 */
    __pyx_t_5 = __pyx_v_k;
    if (__pyx_t_5) {
      __pyx_v_w = __Pyx_c_sum(__pyx_v_w, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((__pyx_v_k * 2) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
      goto __pyx_L14;
    }
    __pyx_L14:;
  }
  __pyx_L4:;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":135
 *     cdef double complex ew, wew, wewz, wn
 *     cdef int i
 *     for i in range(100):             # <<<<<<<<<<<<<<
 *         ew = zexp(w)
 *         wew = w*ew
 */
  for (__pyx_t_6 = 0; __pyx_t_6 < 100; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":136
 *     cdef int i
 *     for i in range(100):
 *         ew = zexp(w)             # <<<<<<<<<<<<<<
 *         wew = w*ew
 *         wewz = wew-z
 */
    __pyx_v_ew = __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_v_w);

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":137
 *     for i in range(100):
 *         ew = zexp(w)
 *         wew = w*ew             # <<<<<<<<<<<<<<
 *         wewz = wew-z
 *         wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
 */
    __pyx_v_wew = __Pyx_c_prod(__pyx_v_w, __pyx_v_ew);

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":138
 *         ew = zexp(w)
 *         wew = w*ew
 *         wewz = wew-z             # <<<<<<<<<<<<<<
 *         wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
 *         if zabs(wn-w) < tol*zabs(wn):
 */
    __pyx_v_wewz = __Pyx_c_diff(__pyx_v_wew, __pyx_v_z);

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":139
 *         wew = w*ew
 *         wewz = wew-z
 *         wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))             # <<<<<<<<<<<<<<
 *         if zabs(wn-w) < tol*zabs(wn):
 *             return wn
 */
    __pyx_v_wn = __Pyx_c_diff(__pyx_v_w, __Pyx_c_quot(__pyx_v_wewz, __Pyx_c_diff(__Pyx_c_sum(__pyx_v_wew, __pyx_v_ew), __Pyx_c_quot(__Pyx_c_prod(__Pyx_c_sum(__pyx_v_w, __pyx_t_double_complex_from_parts(2, 0)), __pyx_v_wewz), __Pyx_c_sum(__Pyx_c_prod(__pyx_t_double_complex_from_parts(2, 0), __pyx_v_w), __pyx_t_double_complex_from_parts(2, 0))))));

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":140
 *         wewz = wew-z
 *         wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
 *         if zabs(wn-w) < tol*zabs(wn):             # <<<<<<<<<<<<<<
 *             return wn
 *         else:
 */
    __pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__Pyx_c_diff(__pyx_v_wn, __pyx_v_w)) < (__pyx_v_tol * __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_wn)));
    if (__pyx_t_1) {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":141
 *         wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
 *         if zabs(wn-w) < tol*zabs(wn):
 *             return wn             # <<<<<<<<<<<<<<
 *         else:
 *             w = wn
 */
      __pyx_r = __pyx_v_wn;
      goto __pyx_L0;
      goto __pyx_L17;
    }
    /*else*/ {

      /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":143
 *             return wn
 *         else:
 *             w = wn             # <<<<<<<<<<<<<<
 * 
 *     lambertw_raise_warning(z)
 */
      __pyx_v_w = __pyx_v_wn;
    }
    __pyx_L17:;
  }

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":145
 *             w = wn
 * 
 *     lambertw_raise_warning(z)             # <<<<<<<<<<<<<<
 *     return wn
 * 
 */
  __pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_v_z);

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":146
 * 
 *     lambertw_raise_warning(z)
 *     return wn             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_wn;
  goto __pyx_L0;

  __pyx_r = __pyx_t_double_complex_from_parts(0, 0);
  __pyx_L0:;
  return __pyx_r;
}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":166
 *         int identity, char* name, char* doc, int c)
 * 
 * cdef void _apply_func_to_1d_vec(char **args, npy_intp *dimensions, npy_intp *steps,             # <<<<<<<<<<<<<<
 *                      void *func) nogil:
 *     cdef npy_intp i
 */

static  void __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec(char **__pyx_v_args, npy_intp *__pyx_v_dimensions, npy_intp *__pyx_v_steps, void *__pyx_v_func) {
  npy_intp __pyx_v_i;
  char *__pyx_v_ip1;
  char *__pyx_v_ip2;
  char *__pyx_v_ip3;
  char *__pyx_v_op;
  npy_intp __pyx_t_1;
  npy_intp __pyx_t_2;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":169
 *                      void *func) nogil:
 *     cdef npy_intp i
 *     cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3]             # <<<<<<<<<<<<<<
 *     for i in range(0, dimensions[0]):
 *         (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
 */
  __pyx_v_ip1 = (__pyx_v_args[0]);
  __pyx_v_ip2 = (__pyx_v_args[1]);
  __pyx_v_ip3 = (__pyx_v_args[2]);
  __pyx_v_op = (__pyx_v_args[3]);

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":170
 *     cdef npy_intp i
 *     cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3]
 *     for i in range(0, dimensions[0]):             # <<<<<<<<<<<<<<
 *         (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
 *             (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
 */
  __pyx_t_1 = (__pyx_v_dimensions[0]);
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_i = __pyx_t_2;

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":171
 *     cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3]
 *     for i in range(0, dimensions[0]):
 *         (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(             # <<<<<<<<<<<<<<
 *             (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
 *         ip1 += steps[0]; ip2 += steps[1]; ip3 += steps[2]; op += steps[3]
 */
    (((__pyx_t_double_complex *)__pyx_v_op)[0]) = ((__pyx_t_double_complex (*)(__pyx_t_double_complex, long, double))__pyx_v_func)((((__pyx_t_double_complex *)__pyx_v_ip1)[0]), (((long *)__pyx_v_ip2)[0]), (((double *)__pyx_v_ip3)[0]));

    /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":173
 *         (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
 *             (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
 *         ip1 += steps[0]; ip2 += steps[1]; ip3 += steps[2]; op += steps[3]             # <<<<<<<<<<<<<<
 * 
 * cdef PyUFuncGenericFunction _loop_funcs[1]
 */
    __pyx_v_ip1 += (__pyx_v_steps[0]);
    __pyx_v_ip2 += (__pyx_v_steps[1]);
    __pyx_v_ip3 += (__pyx_v_steps[2]);
    __pyx_v_op += (__pyx_v_steps[3]);
  }

}

/* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":193
 *     _inp_outp_types, 1, 3, 1, 0, "", "", 0)
 * 
 * def lambertw(z, k=0, tol=1e-8):             # <<<<<<<<<<<<<<
 *     r"""
 *     lambertw(z, k=0, tol=1e-8)
 */

static PyObject *__pyx_pf_5scipy_7special_8lambertw_lambertw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5scipy_7special_8lambertw_lambertw[] = "\n""    lambertw(z, k=0, tol=1e-8)\n""\n""    Lambert W function.\n""\n""    The Lambert W function `W(z)` is defined as the inverse function\n""    of :math:`w \\exp(w)`. In other words, the value of :math:`W(z)` is\n""    such that :math:`z = W(z) \\exp(W(z))` for any complex number\n""    :math:`z`.\n""\n""    The Lambert W function is a multivalued function with infinitely\n""    many branches. Each branch gives a separate solution of the\n""    equation :math:`w \\exp(w)`. Here, the branches are indexed by the\n""    integer `k`.\n""    \n""    Parameters\n""    ----------\n""    z : array_like\n""        Input argument\n""    k : integer, optional\n""        Branch index\n""    tol : float\n""        Evaluation tolerance\n""\n""    Notes\n""    -----\n""    All branches are supported by `lambertw`:\n""\n""    * ``lambertw(z)`` gives the principal solution (branch 0)\n""    * ``lambertw(z, k)`` gives the solution on branch `k`\n""\n""    The Lambert W function has two partially real branches: the\n""    principal branch (`k = 0`) is real for real `z > -1/e`, and the\n""    `k = -1` branch is real for `-1/e < z < 0`. All branches except\n""    `k = 0` have a logarithmic singularity at `z = 0`.\n""\n""    .. rubric:: Possible issues\n""    \n""    The evaluation can become inaccurate very close to the branch point\n""    at `-1/e`. In some corner cases, :func:`lambertw` might currently\n""    fail to converge, or can end up on the wrong branch.\n""\n""    .. rubric:: Algorithm\n""\n""    Halley's iteration is used to invert `w \\exp(w)`, using a first-order\n""    asymptotic approximation (`O(\\log(w))` or `O(w)`) as the initial\n""    estimate.\n""\n""    The definition, implementation and choice of branches is based\n""    on Corless et al, \"On the Lambert W function\", Adv. Comp. Math. 5\n""    (1996) 329-359, available online here:\n""    http://www.apmaths.uwo.ca/~djeffrey/Offprints/W-adv-cm.pdf\n""    \n""    TODO: use a series expansion when extremely close to the branch point\n""    at `-1/e` and make sure that the proper branch is chosen there\n""\n""    Examples\n""    --------\n""    The Lambert W function is the inverse of `w \\exp(w)`::\n""\n""    >>> from scipy.special import lambertw\n""    >>> w = lambertw(1)\n""    >>> w\n""    0.56714329040978387299996866221035555\n""    >>> w*exp(w)\n""    1.0\n""\n""    Any branch gives a valid inverse::\n""\n""    >>> w = lambertw(1, k=3)\n""    >>> w\n""    (-2.8535817554090378072068187234910812 +\n""    17.113535539412145912607826671159289j)\n""    >>> w*exp(w)\n""    (1.0 + 3.5075477124212226194278700785075126e-36j)\n""\n""    .. rubric:: Applications to equation-solving\n""\n""    The Lambert W function may be used to solve various kinds of\n""    equations, such as finding the value of the infinite power\n""    tower `z^{z^{z^{\\ldots}}}`::\n""\n""    >>> def tower(z, n):\n""    ... if n == 0:\n""    ... return z\n""    ... return z ** tower(z, n-1)\n""    ...\n""    >>> tower(0.5, 100)\n""    0.641185744504986\n""    >>> -lambertw(-log(0.5))/log(0.5)\n""    0.6411857445049859844862004821148236665628209571911\n""\n""    .. rubric:: Properties\n""\n""    The Lambert W function grows roughly like the natural logarithm\n""    for large arguments::\n""\n""    >>> lambertw(1000)\n""    5.2496028524016\n""    >>> log(1000)\n""    6.90775527898214\n""    >>> lambertw(10**100)\n""    224.843106445119\n""    >>> log(10**100)\n""    230.258509299405\n""    \n""    The principal branch of the Lambert W function has a rational\n""    Taylor series expansion around `z = 0`::\n""    \n""    >>> nprint(taylor(lambertw, 0, 6), 10)\n""    [0.0, 1.0, -1.0, 1.5, -2.666666667, 5.208333333, -10.8]\n""    \n""    Some special values and limits are::\n""    \n""    >>> lambertw(0)\n""    0.0\n""    >>> lambertw(1)\n""    0.567143290409784\n""    >>> lambertw(e)\n""    1.0\n""    >>> lambertw(inf)\n""    +inf\n""    >>> lambertw(0, k=-1)\n""    -inf\n""    >>> lambertw(0, k=3)\n""    -inf\n""    >>> lambertw(inf, k=3)\n""    (+inf + 18.8495559215388j)\n""\n""    The `k = 0` and `k = -1` branches join at `z = -1/e` where\n""    `W(z) = -1` for both branches. Since `-1/e` can only be represented\n""    approximately with mpmath numbers, evaluating the Lambert W function\n""    at this point only gives `-1` approximately::\n""\n""    >>> lambertw(-1/e, 0)\n""    -0.999999999999837133022867\n""    >>> lambertw(-1/e, -1)\n""    -1.00000000000016286697718\n""    \n""    If `-1/e` happens to round in the negative direction, there might be\n""    a small imaginary part::\n""    \n""    >>> lambertw(-1/e)\n""    (-1.0 + 8.22007971511612e-9j)\n""\n""    ";
static PyObject *__pyx_pf_5scipy_7special_8lambertw_lambertw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_z = 0;
  PyObject *__pyx_v_k = 0;
  PyObject *__pyx_v_tol = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__z,&__pyx_n_s__k,&__pyx_n_s__tol,0};
  __Pyx_RefNannySetupContext("lambertw");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)__pyx_int_0);
    values[2] = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tol);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "lambertw") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_z = values[0];
    __pyx_v_k = values[1];
    __pyx_v_tol = values[2];
  } else {
    __pyx_v_k = ((PyObject *)__pyx_int_0);
    __pyx_v_tol = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_tol = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_k = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_z = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("lambertw", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("scipy.special.lambertw.lambertw");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":340
 * 
 *     """
 *     return _lambertw(z, k, tol)             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___lambertw); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_z);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_z);
  __Pyx_GIVEREF(__pyx_v_z);
  __Pyx_INCREF(__pyx_v_k);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_k);
  __Pyx_GIVEREF(__pyx_v_k);
  __Pyx_INCREF(__pyx_v_tol);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_tol);
  __Pyx_GIVEREF(__pyx_v_tol);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __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_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("scipy.special.lambertw.lambertw");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("lambertw"), (PyCFunction)__pyx_pf_5scipy_7special_8lambertw_lambertw, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5scipy_7special_8lambertw_lambertw)},
  {0, 0, 0, 0}
};

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

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("lambertw"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_u_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 1, 0, 0},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___lambertw, __pyx_k___lambertw, sizeof(__pyx_k___lambertw), 0, 0, 1, 1},
  {&__pyx_n_s__imag, __pyx_k__imag, sizeof(__pyx_k__imag), 0, 0, 1, 1},
  {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1},
  {&__pyx_n_s__lambertw, __pyx_k__lambertw, sizeof(__pyx_k__lambertw), 0, 0, 1, 1},
  {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
  {&__pyx_n_s__real, __pyx_k__real, sizeof(__pyx_k__real), 0, 0, 1, 1},
  {&__pyx_n_s__tol, __pyx_k__tol, sizeof(__pyx_k__tol), 0, 0, 1, 1},
  {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1},
  {&__pyx_n_s__warnings, __pyx_k__warnings, sizeof(__pyx_k__warnings), 0, 0, 1, 1},
  {&__pyx_n_s__z, __pyx_k__z, sizeof(__pyx_k__z), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initlambertw(void); /*proto*/
PyMODINIT_FUNC initlambertw(void)
#else
PyMODINIT_FUNC PyInit_lambertw(void); /*proto*/
PyMODINIT_FUNC PyInit_lambertw(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __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");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_lambertw(void)", __LINE__, __FILE__);
  #endif
  __pyx_init_filenames();
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3
  __pyx_empty_bytes = PyString_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #else
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("lambertw"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_scipy__special__lambertw) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":24
 * 
 * import cython
 * import warnings             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "math.h":
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__warnings), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__warnings, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":176
 * 
 * cdef PyUFuncGenericFunction _loop_funcs[1]
 * _loop_funcs[0] = _apply_func_to_1d_vec             # <<<<<<<<<<<<<<
 * 
 * cdef char _inp_outp_types[4]
 */
  (__pyx_v_5scipy_7special_8lambertw__loop_funcs[0]) = __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":179
 * 
 * cdef char _inp_outp_types[4]
 * _inp_outp_types[0] = NPY_CDOUBLE             # <<<<<<<<<<<<<<
 * _inp_outp_types[1] = NPY_LONG
 * _inp_outp_types[2] = NPY_DOUBLE
 */
  (__pyx_v_5scipy_7special_8lambertw__inp_outp_types[0]) = NPY_CDOUBLE;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":180
 * cdef char _inp_outp_types[4]
 * _inp_outp_types[0] = NPY_CDOUBLE
 * _inp_outp_types[1] = NPY_LONG             # <<<<<<<<<<<<<<
 * _inp_outp_types[2] = NPY_DOUBLE
 * _inp_outp_types[3] = NPY_CDOUBLE
 */
  (__pyx_v_5scipy_7special_8lambertw__inp_outp_types[1]) = NPY_LONG;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":181
 * _inp_outp_types[0] = NPY_CDOUBLE
 * _inp_outp_types[1] = NPY_LONG
 * _inp_outp_types[2] = NPY_DOUBLE             # <<<<<<<<<<<<<<
 * _inp_outp_types[3] = NPY_CDOUBLE
 * 
 */
  (__pyx_v_5scipy_7special_8lambertw__inp_outp_types[2]) = NPY_DOUBLE;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":182
 * _inp_outp_types[1] = NPY_LONG
 * _inp_outp_types[2] = NPY_DOUBLE
 * _inp_outp_types[3] = NPY_CDOUBLE             # <<<<<<<<<<<<<<
 * 
 * import_array()
 */
  (__pyx_v_5scipy_7special_8lambertw__inp_outp_types[3]) = NPY_CDOUBLE;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":184
 * _inp_outp_types[3] = NPY_CDOUBLE
 * 
 * import_array()             # <<<<<<<<<<<<<<
 * import_ufunc()
 * 
 */
  import_array();

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":185
 * 
 * import_array()
 * import_ufunc()             # <<<<<<<<<<<<<<
 * 
 * # The actual ufunc declaration:
 */
  import_ufunc();

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":189
 * # The actual ufunc declaration:
 * cdef void *the_func_to_apply[1]
 * the_func_to_apply[0] = <void*>lambertw_scalar             # <<<<<<<<<<<<<<
 * _lambertw = PyUFunc_FromFuncAndData(_loop_funcs, the_func_to_apply,
 *     _inp_outp_types, 1, 3, 1, 0, "", "", 0)
 */
  (__pyx_v_5scipy_7special_8lambertw_the_func_to_apply[0]) = ((void *)__pyx_f_5scipy_7special_8lambertw_lambertw_scalar);

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":191
 * the_func_to_apply[0] = <void*>lambertw_scalar
 * _lambertw = PyUFunc_FromFuncAndData(_loop_funcs, the_func_to_apply,
 *     _inp_outp_types, 1, 3, 1, 0, "", "", 0)             # <<<<<<<<<<<<<<
 * 
 * def lambertw(z, k=0, tol=1e-8):
 */
  __pyx_t_1 = PyUFunc_FromFuncAndData(__pyx_v_5scipy_7special_8lambertw__loop_funcs, __pyx_v_5scipy_7special_8lambertw_the_func_to_apply, __pyx_v_5scipy_7special_8lambertw__inp_outp_types, 1, 3, 1, 0, __pyx_k_3, __pyx_k_3, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___lambertw, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":193
 *     _inp_outp_types, 1, 3, 1, 0, "", "", 0)
 * 
 * def lambertw(z, k=0, tol=1e-8):             # <<<<<<<<<<<<<<
 *     r"""
 *     lambertw(z, k=0, tol=1e-8)
 */
  __pyx_t_1 = PyFloat_FromDouble(1e-08); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_2 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/pauli/wrk/scipy/scipy/scipy/special/lambertw.pyx":1
 * # Implementation of the Lambert W function [1]. Based on the MPMath             # <<<<<<<<<<<<<<
 * # implementation [2], and documentaion [3].
 * #
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__lambertw); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_4), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init scipy.special.lambertw");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init scipy.special.lambertw");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "lambertw.pyx",
};

/* Runtime support code */

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

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static 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 *number, *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";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
/*
    static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
#if HAVE_HYPOT
        return hypot(z.real, z.imag);
#else
        return sqrt(z.real*z.real + z.imag*z.imag);
#endif
    }
*/
#endif

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    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;
    module = PyObject_CallFunctionObjArgs(__import__,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

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

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp val) {
    const npy_intp neg_one = (npy_intp)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(npy_intp) <  sizeof(long)) {
        return PyInt_FromLong((long)val);
    } else if (sizeof(npy_intp) == sizeof(long)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else { /* (sizeof(npy_intp) > sizeof(long)) */
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    }
}

static CYTHON_INLINE npy_intp __Pyx_PyInt_from_py_npy_intp(PyObject* x) {
    const npy_intp neg_one = (npy_intp)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(npy_intp) == sizeof(char)) {
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(npy_intp) == sizeof(short)) {
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(npy_intp) == sizeof(int)) {
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(npy_intp) == sizeof(long)) {
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(npy_intp) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedLongLong(x);
#if 0
    } else if (sizeof(npy_intp) > sizeof(short) &&
               sizeof(npy_intp) < sizeof(int)) { /*  __int32 ILP64 ? */
        if (is_unsigned)
            return (npy_intp)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (npy_intp)__Pyx_PyInt_AsSignedInt(x);
#endif
    }
    PyErr_SetString(PyExc_TypeError, "npy_intp");
    return (npy_intp)-1;
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

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

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #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_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
