/* Generated by Cython 0.12.1 on Mon May 16 07:44:10 2011 */

#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__sphinxbase
#include "sphinxbase/logmath.h"
#include "sphinxbase/cmd_ln.h"
#include "sphinxbase/ckd_alloc.h"
#include "sphinxbase/fsg_model.h"
#include "sphinxbase/ngram_model.h"
#include "sphinxbase/huff_code.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;


typedef float __pyx_t_10sphinxbase_float32;

typedef int __pyx_t_10sphinxbase_int32;

typedef double __pyx_t_10sphinxbase_float64;

/* Type declarations */

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pxd":149
 *     cdef logmath_t *lmath
 * 
 * cdef class NGramIter:             # <<<<<<<<<<<<<<
 *     cdef NGramModel lm
 *     cdef ngram_iter_t *itor
 */

struct __pyx_obj_10sphinxbase_NGramIter {
  PyObject_HEAD
  struct __pyx_vtabstruct_10sphinxbase_NGramIter *__pyx_vtab;
  struct __pyx_obj_10sphinxbase_NGramModel *lm;
  ngram_iter_t *itor;
  int first_item;
  int m;
  float log_prob;
  float log_bowt;
  PyObject *words;
};

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pxd":159
 *     cdef set_iter(NGramIter self, ngram_iter_t *itor)
 * 
 * cdef class HuffCode:             # <<<<<<<<<<<<<<
 *     cdef huff_code_t *hc
 *     cdef object fh
 */

struct __pyx_obj_10sphinxbase_HuffCode {
  PyObject_HEAD
  huff_code_t *hc;
  PyObject *fh;
};

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pxd":138
 * 
 * # Extension classes
 * cdef class NGramModel:             # <<<<<<<<<<<<<<
 *     cdef ngram_model_t *lm
 *     cdef logmath_t *lmath
 */

struct __pyx_obj_10sphinxbase_NGramModel {
  PyObject_HEAD
  struct __pyx_vtabstruct_10sphinxbase_NGramModel *__pyx_vtab;
  ngram_model_t *lm;
  logmath_t *lmath;
  float lw;
  float wip;
  float uw;
};

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pxd":146
 *     cdef set_lmath(NGramModel self, logmath_t *lmath)
 * 
 * cdef class LogMath:             # <<<<<<<<<<<<<<
 *     cdef logmath_t *lmath
 * 
 */

struct __pyx_obj_10sphinxbase_LogMath {
  PyObject_HEAD
  logmath_t *lmath;
};


/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":390
 *             raise ValueError, "Write %s to file failed" % file_name
 * 
 * cdef class NGramIter:             # <<<<<<<<<<<<<<
 *     """
 *     N-Gram language model iterator class.
 */

struct __pyx_vtabstruct_10sphinxbase_NGramIter {
  PyObject *(*set_iter)(struct __pyx_obj_10sphinxbase_NGramIter *, ngram_iter_t *);
};
static struct __pyx_vtabstruct_10sphinxbase_NGramIter *__pyx_vtabptr_10sphinxbase_NGramIter;


/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":128
 * LOWER = NGRAM_LOWER
 * 
 * cdef class NGramModel:             # <<<<<<<<<<<<<<
 *     """
 *     N-Gram language model class.
 */

struct __pyx_vtabstruct_10sphinxbase_NGramModel {
  PyObject *(*set_lm)(struct __pyx_obj_10sphinxbase_NGramModel *, ngram_model_t *);
  PyObject *(*set_lmath)(struct __pyx_obj_10sphinxbase_NGramModel *, logmath_t *);
};
static struct __pyx_vtabstruct_10sphinxbase_NGramModel *__pyx_vtabptr_10sphinxbase_NGramModel;

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

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (PyList_Append(L, x) < 0) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    }
    else {
        PyObject *r, *m;
        m = __Pyx_GetAttrString(L, "append");
        if (!m) return NULL;
        r = PyObject_CallFunctionObjArgs(m, x, NULL);
        Py_DECREF(m);
        return r;
    }
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void);

static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *); /*proto*/


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
    }
    return r;
}

static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */

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

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

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

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

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

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

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

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

static PyTypeObject *__pyx_ptype_10sphinxbase_NGramModel = 0;
static PyTypeObject *__pyx_ptype_10sphinxbase_LogMath = 0;
static PyTypeObject *__pyx_ptype_10sphinxbase_NGramIter = 0;
static PyTypeObject *__pyx_ptype_10sphinxbase_HuffCode = 0;
#define __Pyx_MODULE_NAME "sphinxbase"
int __pyx_module_is_main_sphinxbase = 0;

/* Implementation of sphinxbase */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_ord;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_RuntimeError;
static char __pyx_k_9[] = "Recode from %s to %s failed";
static char __pyx_k_10[] = "Casefolding failed";
static char __pyx_k_12[] = "Write %s to file failed";
static char __pyx_k_13[] = "";
static char __pyx_k_14[] = "%d";
static char __pyx_k_15[] = "%s";
static char __pyx_k_16[] = "One of alphabet or infile must be passed to constructor";
static char __pyx_k_17[] = "Only one of alphabet or infile must be passed to constructor";
static char __pyx_k_18[] = "Invalid data at position %d";
static char __pyx_k_19[] = "No file is attached";
static char __pyx_k__a[] = "a";
static char __pyx_k__b[] = "b";
static char __pyx_k__m[] = "m";
static char __pyx_k__w[] = "w";
static char __pyx_k__cw[] = "cw";
static char __pyx_k__fh[] = "fh";
static char __pyx_k__hc[] = "hc";
static char __pyx_k__lm[] = "lm";
static char __pyx_k__lw[] = "lw";
static char __pyx_k__rb[] = "rb";
static char __pyx_k__uw[] = "uw";
static char __pyx_k__wb[] = "wb";
static char __pyx_k__DMP[] = "DMP";
static char __pyx_k__min[] = "min";
static char __pyx_k__ord[] = "ord";
static char __pyx_k__too[] = "too";
static char __pyx_k__val[] = "val";
static char __pyx_k__wip[] = "wip";
static char __pyx_k__ARPA[] = "ARPA";
static char __pyx_k__AUTO[] = "AUTO";
static char __pyx_k__base[] = "base";
static char __pyx_k__file[] = "file";
static char __pyx_k__frum[] = "frum";
static char __pyx_k__itor[] = "itor";
static char __pyx_k__mode[] = "mode";
static char __pyx_k__read[] = "read";
static char __pyx_k__word[] = "word";
static char __pyx_k__LOWER[] = "LOWER";
static char __pyx_k__UPPER[] = "UPPER";
static char __pyx_k__lmath[] = "lmath";
static char __pyx_k__lmctl[] = "lmctl";
static char __pyx_k__nbits[] = "nbits";
static char __pyx_k__range[] = "range";
static char __pyx_k__shift[] = "shift";
static char __pyx_k__words[] = "words";
static char __pyx_k__detach[] = "detach";
static char __pyx_k__format[] = "format";
static char __pyx_k__infile[] = "infile";
static char __pyx_k__weight[] = "weight";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k__alphabet[] = "alphabet";
static char __pyx_k__log_bowt[] = "log_bowt";
static char __pyx_k__log_prob[] = "log_prob";
static char __pyx_k__set_iter[] = "set_iter";
static char __pyx_k__enumerate[] = "enumerate";
static char __pyx_k__file_name[] = "file_name";
static char __pyx_k__use_table[] = "use_table";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__first_item[] = "first_item";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__StopIteration[] = "StopIteration";
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_12;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__ARPA;
static PyObject *__pyx_n_s__AUTO;
static PyObject *__pyx_n_s__DMP;
static PyObject *__pyx_n_s__LOWER;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__StopIteration;
static PyObject *__pyx_n_s__UPPER;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s__a;
static PyObject *__pyx_n_s__alphabet;
static PyObject *__pyx_n_s__b;
static PyObject *__pyx_n_s__base;
static PyObject *__pyx_n_s__cw;
static PyObject *__pyx_n_s__detach;
static PyObject *__pyx_n_s__enumerate;
static PyObject *__pyx_n_s__fh;
static PyObject *__pyx_n_s__file;
static PyObject *__pyx_n_s__file_name;
static PyObject *__pyx_n_s__first_item;
static PyObject *__pyx_n_s__format;
static PyObject *__pyx_n_s__frum;
static PyObject *__pyx_n_s__hc;
static PyObject *__pyx_n_s__infile;
static PyObject *__pyx_n_s__itor;
static PyObject *__pyx_n_s__lm;
static PyObject *__pyx_n_s__lmath;
static PyObject *__pyx_n_s__lmctl;
static PyObject *__pyx_n_s__log_bowt;
static PyObject *__pyx_n_s__log_prob;
static PyObject *__pyx_n_s__lw;
static PyObject *__pyx_n_s__m;
static PyObject *__pyx_n_s__min;
static PyObject *__pyx_n_s__mode;
static PyObject *__pyx_n_s__nbits;
static PyObject *__pyx_n_s__ord;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__rb;
static PyObject *__pyx_n_s__read;
static PyObject *__pyx_n_s__set_iter;
static PyObject *__pyx_n_s__shift;
static PyObject *__pyx_n_s__too;
static PyObject *__pyx_n_s__use_table;
static PyObject *__pyx_n_s__uw;
static PyObject *__pyx_n_s__val;
static PyObject *__pyx_n_s__w;
static PyObject *__pyx_n_s__wb;
static PyObject *__pyx_n_s__weight;
static PyObject *__pyx_n_s__wip;
static PyObject *__pyx_n_s__word;
static PyObject *__pyx_n_s__words;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_8;
static PyObject *__pyx_k_1;
static PyObject *__pyx_k_2;
static PyObject *__pyx_k_3;
static PyObject *__pyx_k_4;
static PyObject *__pyx_k_5;
static PyObject *__pyx_k_6;
static PyObject *__pyx_k_7;
static PyObject *__pyx_k_8;
static PyObject *__pyx_k_11;

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":24
 *     @type use_table: bool
 *     """
 *     def __init__(self, base=1.0001, shift=0, use_table=1):             # <<<<<<<<<<<<<<
 *         self.lmath = logmath_init(base, shift, use_table)
 * 
 */

static int __pyx_pf_10sphinxbase_7LogMath___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_10sphinxbase_7LogMath___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_base = 0;
  PyObject *__pyx_v_shift = 0;
  PyObject *__pyx_v_use_table = 0;
  int __pyx_r;
  __pyx_t_10sphinxbase_float64 __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__base,&__pyx_n_s__shift,&__pyx_n_s__use_table,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[0] = __pyx_k_1;
    values[1] = ((PyObject *)__pyx_int_0);
    values[2] = ((PyObject *)__pyx_int_1);
    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:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__base);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shift);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_table);
        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), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_base = values[0];
    __pyx_v_shift = values[1];
    __pyx_v_use_table = values[2];
  } else {
    __pyx_v_base = __pyx_k_1;
    __pyx_v_shift = ((PyObject *)__pyx_int_0);
    __pyx_v_use_table = ((PyObject *)__pyx_int_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_use_table = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_shift = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_base = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.LogMath.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":25
 *     """
 *     def __init__(self, base=1.0001, shift=0, use_table=1):
 *         self.lmath = logmath_init(base, shift, use_table)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_base); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_shift); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_use_table); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath = logmath_init(__pyx_t_1, __pyx_t_2, __pyx_t_3);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("sphinxbase.LogMath.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":27
 *         self.lmath = logmath_init(base, shift, use_table)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         """
 *         Destructor for LogMath class.
 */

static void __pyx_pf_10sphinxbase_7LogMath___dealloc__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath___dealloc__[] = "\n        Destructor for LogMath class.\n        ";
static void __pyx_pf_10sphinxbase_7LogMath___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannySetupContext("__dealloc__");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":31
 *         Destructor for LogMath class.
 *         """
 *         logmath_free(self.lmath)             # <<<<<<<<<<<<<<
 * 
 *     def get_zero(self):
 */
  logmath_free(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath);

  __Pyx_RefNannyFinishContext();
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":33
 *         logmath_free(self.lmath)
 * 
 *     def get_zero(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get the log-zero value.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_get_zero(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_get_zero[] = "\n        Get the log-zero value.\n\n        @return: Smallest number representable by this object.\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_get_zero(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_zero");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":40
 *         @rtype: int
 *         """
 *         return logmath_get_zero(self.lmath)             # <<<<<<<<<<<<<<
 * 
 *     def add(self, a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(logmath_get_zero(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("sphinxbase.LogMath.get_zero");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":42
 *         return logmath_get_zero(self.lmath)
 * 
 *     def add(self, a, b):             # <<<<<<<<<<<<<<
 *         """
 *         Add two numbers in log-space.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_add[] = "\n        Add two numbers in log-space.\n\n        @param a: Logarithm A.\n        @type a: int\n        @param b: Logarithm B.\n        @type b: int\n        @return: log(exp(a)+exp(b))\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_v_b = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__a,&__pyx_n_s__b,0};
  __Pyx_RefNannySetupContext("add");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__b);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("add", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_a = values[0];
    __pyx_v_b = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_a = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_b = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.LogMath.add");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":53
 *         @rtype: int
 *         """
 *         return logmath_add(self.lmath, a, b)             # <<<<<<<<<<<<<<
 * 
 *     def log(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_a); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_b); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyInt_FromLong(logmath_add(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1, __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("sphinxbase.LogMath.add");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":55
 *         return logmath_add(self.lmath, a, b)
 * 
 *     def log(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return log-value of a number.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_log[] = "\n        Return log-value of a number.\n\n        @param x: Number (in linear space)\n        @type x: float\n        @return: Log-value of x.\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  __pyx_t_10sphinxbase_float64 __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("log");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":64
 *         @rtype: int
 *         """
 *         return logmath_log(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 *     def exp(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_x); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromLong(logmath_log(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.log");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":66
 *         return logmath_log(self.lmath, x)
 * 
 *     def exp(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return linear of a log-value
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_exp(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_exp[] = "\n        Return linear of a log-value\n\n        @param x: Logarithm X (in this object's base)\n        @type x: int\n        @return: Exponent (linear value) of X.\n        @rtype: float\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_exp(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("exp");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":75
 *         @rtype: float
 *         """
 *         return logmath_exp(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 *     def log_to_ln(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_x); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyFloat_FromDouble(logmath_exp(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.exp");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":77
 *         return logmath_exp(self.lmath, x)
 * 
 *     def log_to_ln(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return natural logarithm of a log-value.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_log_to_ln(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_log_to_ln[] = "\n        Return natural logarithm of a log-value.\n\n        @param x: Logarithm X (in this object's base)\n        @type x: int\n        @return: Natural log equivalent of x.\n        @rtype: float\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_log_to_ln(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("log_to_ln");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":86
 *         @rtype: float
 *         """
 *         return logmath_log_to_ln(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 *     def log_to_log10(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_x); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyFloat_FromDouble(logmath_log_to_ln(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.log_to_ln");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":88
 *         return logmath_log_to_ln(self.lmath, x)
 * 
 *     def log_to_log10(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return logarithm in base 10 of a log-value.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_log_to_log10(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_log_to_log10[] = "\n        Return logarithm in base 10 of a log-value.\n\n        @param x: Logarithm X (in this object's base)\n        @type x: int\n        @return: log10 equivalent of x.\n        @rtype: float\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_log_to_log10(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("log_to_log10");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":97
 *         @rtype: float
 *         """
 *         return logmath_log_to_log10(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 *     def ln_to_log(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_x); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyFloat_FromDouble(logmath_log_to_log10(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.log_to_log10");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":99
 *         return logmath_log_to_log10(self.lmath, x)
 * 
 *     def ln_to_log(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return log-value of a natural logarithm.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_ln_to_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_ln_to_log[] = "\n        Return log-value of a natural logarithm.\n\n        @param x: Logarithm X (in base e)\n        @type x: float\n        @return: Log-value equivalent of x.\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_ln_to_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  __pyx_t_10sphinxbase_float64 __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("ln_to_log");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":108
 *         @rtype: int
 *         """
 *         return logmath_ln_to_log(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 *     def log10_to_log(self, x):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_x); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromLong(logmath_ln_to_log(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.ln_to_log");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":110
 *         return logmath_ln_to_log(self.lmath, x)
 * 
 *     def log10_to_log(self, x):             # <<<<<<<<<<<<<<
 *         """
 *         Return log-value of a base 10 logarithm.
 */

static PyObject *__pyx_pf_10sphinxbase_7LogMath_log10_to_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/
static char __pyx_doc_10sphinxbase_7LogMath_log10_to_log[] = "\n        Return log-value of a base 10 logarithm.\n\n        @param x: Logarithm X (in base 10)\n        @type x: float\n        @return: Log-value equivalent of x.\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_7LogMath_log10_to_log(PyObject *__pyx_v_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  __pyx_t_10sphinxbase_float64 __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("log10_to_log");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":119
 *         @rtype: int
 *         """
 *         return logmath_log10_to_log(self.lmath, x)             # <<<<<<<<<<<<<<
 * 
 * # Unfortunately, Cython doesn't actually export enums to Python...
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_x); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromLong(logmath_log10_to_log(((struct __pyx_obj_10sphinxbase_LogMath *)__pyx_v_self)->lmath, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.LogMath.log10_to_log");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":146
 *     @type uw: float
 *     """
 *     def __init__(self, file=None, lw=1.0, wip=1.0, uw=1.0, lmctl=None):             # <<<<<<<<<<<<<<
 *         self.lmath = logmath_init(1.0001, 0, 0)
 *         if file:
 */

static int __pyx_pf_10sphinxbase_10NGramModel___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_10sphinxbase_10NGramModel___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_file = 0;
  PyObject *__pyx_v_lw = 0;
  PyObject *__pyx_v_wip = 0;
  PyObject *__pyx_v_uw = 0;
  PyObject *__pyx_v_lmctl = 0;
  int __pyx_r;
  int __pyx_t_1;
  char *__pyx_t_2;
  __pyx_t_10sphinxbase_float32 __pyx_t_3;
  __pyx_t_10sphinxbase_float32 __pyx_t_4;
  __pyx_t_10sphinxbase_float32 __pyx_t_5;
  float __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__file,&__pyx_n_s__lw,&__pyx_n_s__wip,&__pyx_n_s__uw,&__pyx_n_s__lmctl,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = __pyx_k_2;
    values[2] = __pyx_k_3;
    values[3] = __pyx_k_4;
    values[4] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__file);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lw);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__wip);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__uw);
        if (unlikely(value)) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lmctl);
        if (unlikely(value)) { values[4] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_file = values[0];
    __pyx_v_lw = values[1];
    __pyx_v_wip = values[2];
    __pyx_v_uw = values[3];
    __pyx_v_lmctl = values[4];
  } else {
    __pyx_v_file = ((PyObject *)Py_None);
    __pyx_v_lw = __pyx_k_2;
    __pyx_v_wip = __pyx_k_3;
    __pyx_v_uw = __pyx_k_4;
    __pyx_v_lmctl = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: __pyx_v_lmctl = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: __pyx_v_uw = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_wip = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_lw = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_file = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_file);
  __Pyx_INCREF(__pyx_v_lw);
  __Pyx_INCREF(__pyx_v_wip);
  __Pyx_INCREF(__pyx_v_uw);
  __Pyx_INCREF(__pyx_v_lmctl);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":147
 *     """
 *     def __init__(self, file=None, lw=1.0, wip=1.0, uw=1.0, lmctl=None):
 *         self.lmath = logmath_init(1.0001, 0, 0)             # <<<<<<<<<<<<<<
 *         if file:
 *             self.lm = ngram_model_read(NULL, file, NGRAM_AUTO, self.lmath)
 */
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath = logmath_init(1.0001, 0, 0);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":148
 *     def __init__(self, file=None, lw=1.0, wip=1.0, uw=1.0, lmctl=None):
 *         self.lmath = logmath_init(1.0001, 0, 0)
 *         if file:             # <<<<<<<<<<<<<<
 *             self.lm = ngram_model_read(NULL, file, NGRAM_AUTO, self.lmath)
 *             ngram_model_apply_weights(self.lm, lw, wip, uw)
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_file); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":149
 *         self.lmath = logmath_init(1.0001, 0, 0)
 *         if file:
 *             self.lm = ngram_model_read(NULL, file, NGRAM_AUTO, self.lmath)             # <<<<<<<<<<<<<<
 *             ngram_model_apply_weights(self.lm, lw, wip, uw)
 *         elif lmctl:
 */
    __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_file); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm = ngram_model_read(NULL, __pyx_t_2, NGRAM_AUTO, ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath);

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":150
 *         if file:
 *             self.lm = ngram_model_read(NULL, file, NGRAM_AUTO, self.lmath)
 *             ngram_model_apply_weights(self.lm, lw, wip, uw)             # <<<<<<<<<<<<<<
 *         elif lmctl:
 *             self.lm = ngram_model_set_read(NULL, lmctl, self.lmath)
 */
    __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_lw); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_wip); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __pyx_PyFloat_AsDouble(__pyx_v_uw); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ngram_model_apply_weights(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_3, __pyx_t_4, __pyx_t_5);
    goto __pyx_L6;
  }

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":151
 *             self.lm = ngram_model_read(NULL, file, NGRAM_AUTO, self.lmath)
 *             ngram_model_apply_weights(self.lm, lw, wip, uw)
 *         elif lmctl:             # <<<<<<<<<<<<<<
 *             self.lm = ngram_model_set_read(NULL, lmctl, self.lmath)
 *         else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_lmctl); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":152
 *             ngram_model_apply_weights(self.lm, lw, wip, uw)
 *         elif lmctl:
 *             self.lm = ngram_model_set_read(NULL, lmctl, self.lmath)             # <<<<<<<<<<<<<<
 *         else:
 *             self.lm = NULL
 */
    __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_lmctl); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm = ngram_model_set_read(NULL, __pyx_t_2, ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":154
 *             self.lm = ngram_model_set_read(NULL, lmctl, self.lmath)
 *         else:
 *             self.lm = NULL             # <<<<<<<<<<<<<<
 *         self.lw = lw
 *         self.wip = wip
 */
    ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm = NULL;
  }
  __pyx_L6:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":155
 *         else:
 *             self.lm = NULL
 *         self.lw = lw             # <<<<<<<<<<<<<<
 *         self.wip = wip
 *         self.uw = uw
 */
  __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_lw); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lw = __pyx_t_6;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":156
 *             self.lm = NULL
 *         self.lw = lw
 *         self.wip = wip             # <<<<<<<<<<<<<<
 *         self.uw = uw
 * 
 */
  __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_wip); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->wip = __pyx_t_6;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":157
 *         self.lw = lw
 *         self.wip = wip
 *         self.uw = uw             # <<<<<<<<<<<<<<
 * 
 *     cdef set_lm(NGramModel self, ngram_model_t *lm):
 */
  __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_uw); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->uw = __pyx_t_6;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_file);
  __Pyx_DECREF(__pyx_v_lw);
  __Pyx_DECREF(__pyx_v_wip);
  __Pyx_DECREF(__pyx_v_uw);
  __Pyx_DECREF(__pyx_v_lmctl);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":159
 *         self.uw = uw
 * 
 *     cdef set_lm(NGramModel self, ngram_model_t *lm):             # <<<<<<<<<<<<<<
 *         ngram_model_retain(lm)
 *         ngram_model_free(self.lm)
 */

static  PyObject *__pyx_f_10sphinxbase_10NGramModel_set_lm(struct __pyx_obj_10sphinxbase_NGramModel *__pyx_v_self, ngram_model_t *__pyx_v_lm) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("set_lm");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":160
 * 
 *     cdef set_lm(NGramModel self, ngram_model_t *lm):
 *         ngram_model_retain(lm)             # <<<<<<<<<<<<<<
 *         ngram_model_free(self.lm)
 *         self.lm = lm
 */
  ngram_model_retain(__pyx_v_lm);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":161
 *     cdef set_lm(NGramModel self, ngram_model_t *lm):
 *         ngram_model_retain(lm)
 *         ngram_model_free(self.lm)             # <<<<<<<<<<<<<<
 *         self.lm = lm
 * 
 */
  ngram_model_free(__pyx_v_self->lm);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":162
 *         ngram_model_retain(lm)
 *         ngram_model_free(self.lm)
 *         self.lm = lm             # <<<<<<<<<<<<<<
 * 
 *     cdef set_lmath(NGramModel self, logmath_t *lmath):
 */
  __pyx_v_self->lm = __pyx_v_lm;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":164
 *         self.lm = lm
 * 
 *     cdef set_lmath(NGramModel self, logmath_t *lmath):             # <<<<<<<<<<<<<<
 *         logmath_retain(lmath)
 *         logmath_free(self.lmath)
 */

static  PyObject *__pyx_f_10sphinxbase_10NGramModel_set_lmath(struct __pyx_obj_10sphinxbase_NGramModel *__pyx_v_self, logmath_t *__pyx_v_lmath) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("set_lmath");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":165
 * 
 *     cdef set_lmath(NGramModel self, logmath_t *lmath):
 *         logmath_retain(lmath)             # <<<<<<<<<<<<<<
 *         logmath_free(self.lmath)
 *         self.lmath = lmath
 */
  logmath_retain(__pyx_v_lmath);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":166
 *     cdef set_lmath(NGramModel self, logmath_t *lmath):
 *         logmath_retain(lmath)
 *         logmath_free(self.lmath)             # <<<<<<<<<<<<<<
 *         self.lmath = lmath
 * 
 */
  logmath_free(__pyx_v_self->lmath);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":167
 *         logmath_retain(lmath)
 *         logmath_free(self.lmath)
 *         self.lmath = lmath             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->lmath = __pyx_v_lmath;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":169
 *         self.lmath = lmath
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         """
 *         Destructor for N-Gram model class.
 */

static void __pyx_pf_10sphinxbase_10NGramModel___dealloc__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel___dealloc__[] = "\n        Destructor for N-Gram model class.\n        ";
static void __pyx_pf_10sphinxbase_10NGramModel___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannySetupContext("__dealloc__");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":173
 *         Destructor for N-Gram model class.
 *         """
 *         logmath_free(self.lmath)             # <<<<<<<<<<<<<<
 *         ngram_model_free(self.lm)
 * 
 */
  logmath_free(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":174
 *         """
 *         logmath_free(self.lmath)
 *         ngram_model_free(self.lm)             # <<<<<<<<<<<<<<
 * 
 *     def apply_weights(self, lw=1.0, wip=1.0, uw=1.0):
 */
  ngram_model_free(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm);

  __Pyx_RefNannyFinishContext();
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":176
 *         ngram_model_free(self.lm)
 * 
 *     def apply_weights(self, lw=1.0, wip=1.0, uw=1.0):             # <<<<<<<<<<<<<<
 *         """
 *         Change the language model weights applied in L{score}.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_apply_weights(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_apply_weights[] = "\n        Change the language model weights applied in L{score}.\n        \n        @param lw: Language weight to apply to model probabilities.\n        @type lw: float\n        @param wip: Word insertion penalty to add to model probabilities\n        @type wip: float\n        @param uw: Weight to give unigrams when interpolating with uniform distribution.\n        @type uw: float\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_apply_weights(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_lw = 0;
  PyObject *__pyx_v_wip = 0;
  PyObject *__pyx_v_uw = 0;
  PyObject *__pyx_r = NULL;
  float __pyx_t_1;
  __pyx_t_10sphinxbase_float32 __pyx_t_2;
  __pyx_t_10sphinxbase_float32 __pyx_t_3;
  __pyx_t_10sphinxbase_float32 __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lw,&__pyx_n_s__wip,&__pyx_n_s__uw,0};
  __Pyx_RefNannySetupContext("apply_weights");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[0] = __pyx_k_5;
    values[1] = __pyx_k_6;
    values[2] = __pyx_k_7;
    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:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lw);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__wip);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__uw);
        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), "apply_weights") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_lw = values[0];
    __pyx_v_wip = values[1];
    __pyx_v_uw = values[2];
  } else {
    __pyx_v_lw = __pyx_k_5;
    __pyx_v_wip = __pyx_k_6;
    __pyx_v_uw = __pyx_k_7;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: __pyx_v_uw = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_wip = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_lw = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("apply_weights", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.apply_weights");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":187
 *         @type uw: float
 *         """
 *         self.lw = lw             # <<<<<<<<<<<<<<
 *         self.wip = wip
 *         self.uw = uw
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_lw); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lw = __pyx_t_1;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":188
 *         """
 *         self.lw = lw
 *         self.wip = wip             # <<<<<<<<<<<<<<
 *         self.uw = uw
 *         ngram_model_apply_weights(self.lm, lw, wip, uw)
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_wip); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->wip = __pyx_t_1;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":189
 *         self.lw = lw
 *         self.wip = wip
 *         self.uw = uw             # <<<<<<<<<<<<<<
 *         ngram_model_apply_weights(self.lm, lw, wip, uw)
 * 
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_uw); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->uw = __pyx_t_1;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":190
 *         self.wip = wip
 *         self.uw = uw
 *         ngram_model_apply_weights(self.lm, lw, wip, uw)             # <<<<<<<<<<<<<<
 * 
 *     def get_size(self):
 */
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_lw); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_wip); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_uw); if (unlikely((__pyx_t_4 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ngram_model_apply_weights(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_2, __pyx_t_3, __pyx_t_4);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.apply_weights");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":192
 *         ngram_model_apply_weights(self.lm, lw, wip, uw)
 * 
 *     def get_size(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get the order of this model (i.e. the 'N' in 'N-gram')
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_get_size(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_get_size[] = "\n        Get the order of this model (i.e. the 'N' in 'N-gram')\n\n        @return: Order of this model\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_get_size(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("get_size");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":199
 *         @rtype: int
 *         """
 *         return ngram_model_get_size(self.lm)             # <<<<<<<<<<<<<<
 * 
 *     def get_counts(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(ngram_model_get_size(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("sphinxbase.NGramModel.get_size");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":201
 *         return ngram_model_get_size(self.lm)
 * 
 *     def get_counts(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get the counts of each size of N-gram.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_get_counts(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_get_counts[] = "\n        Get the counts of each size of N-gram.\n\n        @return: Counts of 1, 2, ..., N grams\n        @rtype: tuple(int)\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_get_counts(PyObject *__pyx_v_self, PyObject *unused) {
  int *__pyx_v_counts;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("get_counts");
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":209
 *         """
 *         cdef int *counts
 *         counts = ngram_model_get_counts(self.lm)             # <<<<<<<<<<<<<<
 *         return tuple([counts[i] for i in range(ngram_model_get_size(self.lm))])
 * 
 */
  __pyx_v_counts = ngram_model_get_counts(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":210
 *         cdef int *counts
 *         counts = ngram_model_get_counts(self.lm)
 *         return tuple([counts[i] for i in range(ngram_model_get_size(self.lm))])             # <<<<<<<<<<<<<<
 * 
 *     def unknown_wid(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyInt_FromLong(ngram_model_get_size(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = 0; __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4);
  } else {
    __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_4))) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_4))) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_4);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyInt_FromLong((__pyx_v_counts[__pyx_t_5])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_3); if (unlikely(__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 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_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.NGramModel.get_counts");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":212
 *         return tuple([counts[i] for i in range(ngram_model_get_size(self.lm))])
 * 
 *     def unknown_wid(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get the ID for an unknown word.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_unknown_wid(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_unknown_wid[] = "\n        Get the ID for an unknown word.\n\n        In the case of a closed-vocabulary language model this will be -1.\n\n        @return: Word ID for the unknown word.\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_unknown_wid(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("unknown_wid");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":221
 *         @rtype: int
 *         """
 *         return ngram_unknown_wid(self.lm)             # <<<<<<<<<<<<<<
 * 
 *     def zero(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(ngram_unknown_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("sphinxbase.NGramModel.unknown_wid");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":223
 *         return ngram_unknown_wid(self.lm)
 * 
 *     def zero(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get the log-zero value for this language model.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_zero(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_zero[] = "\n        Get the log-zero value for this language model.\n\n        @return: Log value used to represent zero.\n        @rtype: float\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_zero(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("zero");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":230
 *         @rtype: float
 *         """
 *         return logmath_log_to_ln(self.lmath, ngram_zero(self.lm))             # <<<<<<<<<<<<<<
 * 
 *     def wid(self, word):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(logmath_log_to_ln(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath, ngram_zero(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("sphinxbase.NGramModel.zero");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":232
 *         return logmath_log_to_ln(self.lmath, ngram_zero(self.lm))
 * 
 *     def wid(self, word):             # <<<<<<<<<<<<<<
 *         """
 *         Get the internal ID for a word.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_wid(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_wid[] = "\n        Get the internal ID for a word.\n        \n        @param word: Word in question\n        @type word: string\n        @return: Internal ID for word, or -1 if not present\n        @rtype: int\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_wid(PyObject *__pyx_v_self, PyObject *__pyx_v_word) {
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("wid");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":241
 *         @rtype: int
 *         """
 *         return ngram_wid(self.lm, word)             # <<<<<<<<<<<<<<
 * 
 *     def word(self, wid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromLong(ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.NGramModel.wid");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":243
 *         return ngram_wid(self.lm, word)
 * 
 *     def word(self, wid):             # <<<<<<<<<<<<<<
 *         """
 *         Get the string corresponding to an internal word ID.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_word(PyObject *__pyx_v_self, PyObject *__pyx_v_wid); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_word[] = "\n        Get the string corresponding to an internal word ID.\n        \n        @param word: Word ID in question\n        @type word: int\n        @return: String for word, or None if not present\n        @rtype: string\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_word(PyObject *__pyx_v_self, PyObject *__pyx_v_wid) {
  PyObject *__pyx_r = NULL;
  __pyx_t_10sphinxbase_int32 __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("word");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":252
 *         @rtype: string
 *         """
 *         return ngram_word(self.lm, wid)             # <<<<<<<<<<<<<<
 * 
 *     # Note that this and prob() are almost exactly the same...
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_wid); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyBytes_FromString(ngram_word(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.NGramModel.word");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":255
 * 
 *     # Note that this and prob() are almost exactly the same...
 *     def score(self, word, *args):             # <<<<<<<<<<<<<<
 *         """
 *         Get the score for an N-Gram.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_score[] = "\n        Get the score for an N-Gram.\n\n        The argument list consists of the history words (as\n        null-terminated strings) of the N-Gram, in reverse order.\n        Therefore, if you wanted to get the N-Gram score for 'a whole\n        joy', you would call::\n\n         score, n_used = model.score('joy', 'whole', 'a')\n\n        This function returns a tuple, consisting of the score and the\n        number of words used in computing it (i.e. the effective size\n        of the N-Gram).  The score is returned in logarithmic form,\n        using base e.\n\n        If one of the words is not in the LM's vocabulary, the result\n        will depend on whether this is an open or closed vocabulary\n        language model.  For an open-vocabulary model, unknown words\n        are all mapped to the unigram <UNK> which has a non-zero\n        probability and also participates in higher-order N-Grams.\n        Therefore, you will get a score of some sort in this case.\n\n        For a closed-vocabulary model, unknown words are impossible\n        and thus have zero probability.  Therefore, if C{word} is\n        unknown, this function will return a 'zero' log-probability,\n        i.e. a large negative number.\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_word = 0;
  PyObject *__pyx_v_args = 0;
  __pyx_t_10sphinxbase_int32 __pyx_v_wid;
  __pyx_t_10sphinxbase_int32 *__pyx_v_hist;
  __pyx_t_10sphinxbase_int32 __pyx_v_n_hist;
  __pyx_t_10sphinxbase_int32 __pyx_v_n_used;
  __pyx_t_10sphinxbase_int32 __pyx_v_score;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_spam;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  __pyx_t_10sphinxbase_int32 __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,0};
  __Pyx_RefNannySetupContext("score");
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 1) ? PyTuple_GET_SIZE(__pyx_args) : 1;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "score") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_word = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_word = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("score", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("sphinxbase.NGramModel.score");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_word);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_spam = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":288
 *         cdef int32 n_used
 *         cdef int32 score
 *         wid = ngram_wid(self.lm, word)             # <<<<<<<<<<<<<<
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_wid = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":289
 *         cdef int32 score
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)             # <<<<<<<<<<<<<<
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_n_hist = __pyx_t_2;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":290
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 */
  __pyx_v_hist = ((__pyx_t_10sphinxbase_int32 *)ckd_calloc(__pyx_v_n_hist, (sizeof(__pyx_t_10sphinxbase_int32))));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":291
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_3 = __pyx_v_n_hist;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":292
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]             # <<<<<<<<<<<<<<
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_score(self.lm, wid, hist, n_hist, &n_used)
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_v_args, __pyx_v_i); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_spam);
    __pyx_v_spam = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":293
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)             # <<<<<<<<<<<<<<
 *         score = ngram_ng_score(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)
 */
    __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_spam); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_hist[__pyx_t_2]) = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":291
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_v_i);
  __pyx_v_i = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":294
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_score(self.lm, wid, hist, n_hist, &n_used)             # <<<<<<<<<<<<<<
 *         ckd_free(hist)
 *         return logmath_log_to_ln(self.lmath, score), n_used
 */
  __pyx_v_score = ngram_ng_score(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_v_wid, __pyx_v_hist, __pyx_v_n_hist, (&__pyx_v_n_used));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":295
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_score(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)             # <<<<<<<<<<<<<<
 *         return logmath_log_to_ln(self.lmath, score), n_used
 * 
 */
  ckd_free(__pyx_v_hist);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":296
 *         score = ngram_ng_score(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)
 *         return logmath_log_to_ln(self.lmath, score), n_used             # <<<<<<<<<<<<<<
 * 
 *     def prob(self, word, *args):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyFloat_FromDouble(logmath_log_to_ln(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath, __pyx_v_score)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyInt_FromLong(__pyx_v_n_used); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("sphinxbase.NGramModel.score");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_spam);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_word);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":298
 *         return logmath_log_to_ln(self.lmath, score), n_used
 * 
 *     def prob(self, word, *args):             # <<<<<<<<<<<<<<
 *         """
 *         Get the log-probability for an N-Gram.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_prob(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_prob[] = "\n        Get the log-probability for an N-Gram.\n\n        This works effectively the same way as L{score}, except that\n        any weights (language weight, insertion penalty) applied to\n        the language model are ignored and the 'raw' probability value\n        is returned.\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_prob(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_word = 0;
  PyObject *__pyx_v_args = 0;
  __pyx_t_10sphinxbase_int32 __pyx_v_wid;
  __pyx_t_10sphinxbase_int32 *__pyx_v_hist;
  __pyx_t_10sphinxbase_int32 __pyx_v_n_hist;
  __pyx_t_10sphinxbase_int32 __pyx_v_n_used;
  __pyx_t_10sphinxbase_int32 __pyx_v_score;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_spam;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  __pyx_t_10sphinxbase_int32 __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,0};
  __Pyx_RefNannySetupContext("prob");
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 1) ? PyTuple_GET_SIZE(__pyx_args) : 1;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "prob") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_word = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_word = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("prob", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("sphinxbase.NGramModel.prob");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_word);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_spam = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":312
 *         cdef int32 n_used
 *         cdef int32 score
 *         wid = ngram_wid(self.lm, word)             # <<<<<<<<<<<<<<
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_wid = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":313
 *         cdef int32 score
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)             # <<<<<<<<<<<<<<
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_n_hist = __pyx_t_2;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":314
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 */
  __pyx_v_hist = ((__pyx_t_10sphinxbase_int32 *)ckd_calloc(__pyx_v_n_hist, (sizeof(__pyx_t_10sphinxbase_int32))));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":315
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_3 = __pyx_v_n_hist;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":316
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]             # <<<<<<<<<<<<<<
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_prob(self.lm, wid, hist, n_hist, &n_used)
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_v_args, __pyx_v_i); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_spam);
    __pyx_v_spam = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":317
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)             # <<<<<<<<<<<<<<
 *         score = ngram_ng_prob(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)
 */
    __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_spam); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_hist[__pyx_t_2]) = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":315
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_v_i);
  __pyx_v_i = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":318
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_prob(self.lm, wid, hist, n_hist, &n_used)             # <<<<<<<<<<<<<<
 *         ckd_free(hist)
 *         return logmath_log_to_ln(self.lmath, score), n_used
 */
  __pyx_v_score = ngram_ng_prob(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_v_wid, __pyx_v_hist, __pyx_v_n_hist, (&__pyx_v_n_used));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":319
 *             hist[i] = ngram_wid(self.lm, spam)
 *         score = ngram_ng_prob(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)             # <<<<<<<<<<<<<<
 *         return logmath_log_to_ln(self.lmath, score), n_used
 * 
 */
  ckd_free(__pyx_v_hist);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":320
 *         score = ngram_ng_prob(self.lm, wid, hist, n_hist, &n_used)
 *         ckd_free(hist)
 *         return logmath_log_to_ln(self.lmath, score), n_used             # <<<<<<<<<<<<<<
 * 
 *     def mgrams(self, m):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyFloat_FromDouble(logmath_log_to_ln(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lmath, __pyx_v_score)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyInt_FromLong(__pyx_v_n_used); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("sphinxbase.NGramModel.prob");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_spam);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_word);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":322
 *         return logmath_log_to_ln(self.lmath, score), n_used
 * 
 *     def mgrams(self, m):             # <<<<<<<<<<<<<<
 *         """
 *         Return an iterator over each N-gram of order m+1.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_mgrams(PyObject *__pyx_v_self, PyObject *__pyx_v_m); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_mgrams[] = "\n        Return an iterator over each N-gram of order m+1.\n\n        This allows Pythonic iteration over the parameters of an\n        N-Gram model.\n\n        @param m: Order of requested N-grams minus one\n        @type m: int\n        @return: Iterator over M+1-grams\n        @rtype: NGramIter\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_mgrams(PyObject *__pyx_v_self, PyObject *__pyx_v_m) {
  struct __pyx_obj_10sphinxbase_NGramIter *__pyx_v_itor;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("mgrams");
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":335
 *         """
 *         cdef NGramIter itor
 *         itor = NGramIter(self, m)             # <<<<<<<<<<<<<<
 *         itor.itor = ngram_model_mgrams(self.lm, m)
 *         return itor
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_m);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_m);
  __Pyx_GIVEREF(__pyx_v_m);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10sphinxbase_NGramIter)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_itor));
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":336
 *         cdef NGramIter itor
 *         itor = NGramIter(self, m)
 *         itor.itor = ngram_model_mgrams(self.lm, m)             # <<<<<<<<<<<<<<
 *         return itor
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_m); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_itor->itor = ngram_model_mgrams(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_3);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":337
 *         itor = NGramIter(self, m)
 *         itor.itor = ngram_model_mgrams(self.lm, m)
 *         return itor             # <<<<<<<<<<<<<<
 * 
 *     def ngram(self, word, *args):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_itor));
  __pyx_r = ((PyObject *)__pyx_v_itor);
  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_AddTraceback("sphinxbase.NGramModel.mgrams");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_itor);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":339
 *         return itor
 * 
 *     def ngram(self, word, *args):             # <<<<<<<<<<<<<<
 *         """
 *         Return an N-Gram iterator pointing to a given N-gram.
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_ngram(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_10NGramModel_ngram[] = "\n        Return an N-Gram iterator pointing to a given N-gram.\n\n        This allows you to iterate over its successors among other\n        things.\n\n        @param word: Head word of requested N-gram.\n        @type word: str\n        @param args: History words of requested N-gram\n        @type args: str\n        @return: Iterator pointing to N-gram.\n        ";
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_ngram(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_word = 0;
  PyObject *__pyx_v_args = 0;
  struct __pyx_obj_10sphinxbase_NGramIter *__pyx_v_itor;
  __pyx_t_10sphinxbase_int32 __pyx_v_wid;
  __pyx_t_10sphinxbase_int32 *__pyx_v_hist;
  __pyx_t_10sphinxbase_int32 __pyx_v_n_hist;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_spam;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  __pyx_t_10sphinxbase_int32 __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,0};
  __Pyx_RefNannySetupContext("ngram");
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 1) ? PyTuple_GET_SIZE(__pyx_args) : 1;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "ngram") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_word = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_word = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ngram", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("sphinxbase.NGramModel.ngram");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_word);
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_spam = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":356
 *         cdef int32 *hist
 *         cdef int32 n_hist
 *         wid = ngram_wid(self.lm, word)             # <<<<<<<<<<<<<<
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_wid = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":357
 *         cdef int32 n_hist
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)             # <<<<<<<<<<<<<<
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_n_hist = __pyx_t_2;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":358
 *         wid = ngram_wid(self.lm, word)
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 */
  __pyx_v_hist = ((__pyx_t_10sphinxbase_int32 *)ckd_calloc(__pyx_v_n_hist, (sizeof(__pyx_t_10sphinxbase_int32))));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":359
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_3 = __pyx_v_n_hist;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":360
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]             # <<<<<<<<<<<<<<
 *             hist[i] = ngram_wid(self.lm, spam)
 *         itor = NGramIter(self, n_hist)
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_v_args, __pyx_v_i); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_v_spam);
    __pyx_v_spam = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":361
 *         for i from 0 <= i < n_hist:
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)             # <<<<<<<<<<<<<<
 *         itor = NGramIter(self, n_hist)
 *         # We do set_iter here, because we're returning something the
 */
    __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_spam); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_hist[__pyx_t_2]) = ngram_wid(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":359
 *         n_hist = len(args)
 *         hist = <int32 *>ckd_calloc(n_hist, sizeof(int32))
 *         for i from 0 <= i < n_hist:             # <<<<<<<<<<<<<<
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_v_i);
  __pyx_v_i = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":362
 *             spam = args[i]
 *             hist[i] = ngram_wid(self.lm, spam)
 *         itor = NGramIter(self, n_hist)             # <<<<<<<<<<<<<<
 *         # We do set_iter here, because we're returning something the
 *         # user is immediately going to do stuff with.
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n_hist); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10sphinxbase_NGramIter)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_itor));
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":365
 *         # We do set_iter here, because we're returning something the
 *         # user is immediately going to do stuff with.
 *         itor.set_iter(ngram_ng_iter(self.lm, wid, hist, n_hist))             # <<<<<<<<<<<<<<
 *         ckd_free(hist)
 *         return itor
 */
  __pyx_t_5 = ((struct __pyx_vtabstruct_10sphinxbase_NGramIter *)__pyx_v_itor->__pyx_vtab)->set_iter(__pyx_v_itor, ngram_ng_iter(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_v_wid, __pyx_v_hist, __pyx_v_n_hist)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":366
 *         # user is immediately going to do stuff with.
 *         itor.set_iter(ngram_ng_iter(self.lm, wid, hist, n_hist))
 *         ckd_free(hist)             # <<<<<<<<<<<<<<
 *         return itor
 * 
 */
  ckd_free(__pyx_v_hist);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":367
 *         itor.set_iter(ngram_ng_iter(self.lm, wid, hist, n_hist))
 *         ckd_free(hist)
 *         return itor             # <<<<<<<<<<<<<<
 * 
 *     def add_word(self, word, weight=1.0):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_itor));
  __pyx_r = ((PyObject *)__pyx_v_itor);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("sphinxbase.NGramModel.ngram");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF((PyObject *)__pyx_v_itor);
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_spam);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_word);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":369
 *         return itor
 * 
 *     def add_word(self, word, weight=1.0):             # <<<<<<<<<<<<<<
 *         return ngram_model_add_word(self.lm, word, weight)
 * 
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_add_word(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_add_word(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_word = 0;
  PyObject *__pyx_v_weight = 0;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  __pyx_t_10sphinxbase_float32 __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,&__pyx_n_s__weight,0};
  __Pyx_RefNannySetupContext("add_word");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_8;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__weight);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_word") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_word = values[0];
    __pyx_v_weight = values[1];
  } else {
    __pyx_v_weight = __pyx_k_8;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_weight = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_word = 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("add_word", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.add_word");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":370
 * 
 *     def add_word(self, word, weight=1.0):
 *         return ngram_model_add_word(self.lm, word, weight)             # <<<<<<<<<<<<<<
 * 
 *     def recode(self, frum, too):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_weight); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyInt_FromLong(ngram_model_add_word(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1, __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("sphinxbase.NGramModel.add_word");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":372
 *         return ngram_model_add_word(self.lm, word, weight)
 * 
 *     def recode(self, frum, too):             # <<<<<<<<<<<<<<
 *         cdef int rv
 *         rv = ngram_model_recode(self.lm, frum, too)
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_recode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_recode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_frum = 0;
  PyObject *__pyx_v_too = 0;
  int __pyx_v_rv;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__frum,&__pyx_n_s__too,0};
  __Pyx_RefNannySetupContext("recode");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__frum);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__too);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("recode", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "recode") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_frum = values[0];
    __pyx_v_too = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_frum = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_too = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("recode", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.recode");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_frum);
  __Pyx_INCREF(__pyx_v_too);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":374
 *     def recode(self, frum, too):
 *         cdef int rv
 *         rv = ngram_model_recode(self.lm, frum, too)             # <<<<<<<<<<<<<<
 *         if rv == -1:
 *             raise ValueError, "Recode from %s to %s failed" % (frum, too)
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_frum); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_too); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rv = ngram_model_recode(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1, __pyx_t_2);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":375
 *         cdef int rv
 *         rv = ngram_model_recode(self.lm, frum, too)
 *         if rv == -1:             # <<<<<<<<<<<<<<
 *             raise ValueError, "Recode from %s to %s failed" % (frum, too)
 * 
 */
  __pyx_t_3 = (__pyx_v_rv == -1);
  if (__pyx_t_3) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":376
 *         rv = ngram_model_recode(self.lm, frum, too)
 *         if rv == -1:
 *             raise ValueError, "Recode from %s to %s failed" % (frum, too)             # <<<<<<<<<<<<<<
 * 
 *     def casefold(self, kase):
 */
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_frum);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_frum);
    __Pyx_GIVEREF(__pyx_v_frum);
    __Pyx_INCREF(__pyx_v_too);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_too);
    __Pyx_GIVEREF(__pyx_v_too);
    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_builtin_ValueError, __pyx_t_5, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("sphinxbase.NGramModel.recode");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_frum);
  __Pyx_DECREF(__pyx_v_too);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":378
 *             raise ValueError, "Recode from %s to %s failed" % (frum, too)
 * 
 *     def casefold(self, kase):             # <<<<<<<<<<<<<<
 *         cdef int rv
 *         rv = ngram_model_casefold(self.lm, kase)
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_casefold(PyObject *__pyx_v_self, PyObject *__pyx_v_kase); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_casefold(PyObject *__pyx_v_self, PyObject *__pyx_v_kase) {
  int __pyx_v_rv;
  PyObject *__pyx_r = NULL;
  ngram_case_t __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("casefold");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_kase);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":380
 *     def casefold(self, kase):
 *         cdef int rv
 *         rv = ngram_model_casefold(self.lm, kase)             # <<<<<<<<<<<<<<
 *         if rv == -1:
 *             raise ValueError, "Casefolding failed"
 */
  __pyx_t_1 = ((ngram_case_t)PyInt_AsLong(__pyx_v_kase)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rv = ngram_model_casefold(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":381
 *         cdef int rv
 *         rv = ngram_model_casefold(self.lm, kase)
 *         if rv == -1:             # <<<<<<<<<<<<<<
 *             raise ValueError, "Casefolding failed"
 * 
 */
  __pyx_t_2 = (__pyx_v_rv == -1);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":382
 *         rv = ngram_model_casefold(self.lm, kase)
 *         if rv == -1:
 *             raise ValueError, "Casefolding failed"             # <<<<<<<<<<<<<<
 * 
 *     def write(self, file_name, format=NGRAM_AUTO):
 */
    __Pyx_Raise(__pyx_builtin_ValueError, ((PyObject *)__pyx_kp_s_10), 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.casefold");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_kase);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":384
 *             raise ValueError, "Casefolding failed"
 * 
 *     def write(self, file_name, format=NGRAM_AUTO):             # <<<<<<<<<<<<<<
 *         cdef int rv
 *         rv = ngram_model_write(self.lm, file_name, format)
 */

static PyObject *__pyx_pf_10sphinxbase_10NGramModel_write(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_10NGramModel_write(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_file_name = 0;
  PyObject *__pyx_v_format = 0;
  int __pyx_v_rv;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  ngram_file_type_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__file_name,&__pyx_n_s__format,0};
  __Pyx_RefNannySetupContext("write");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_11;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__file_name);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__format);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "write") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_file_name = values[0];
    __pyx_v_format = values[1];
  } else {
    __pyx_v_format = __pyx_k_11;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_format = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_file_name = 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("write", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramModel.write");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_file_name);
  __Pyx_INCREF(__pyx_v_format);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":386
 *     def write(self, file_name, format=NGRAM_AUTO):
 *         cdef int rv
 *         rv = ngram_model_write(self.lm, file_name, format)             # <<<<<<<<<<<<<<
 *         if rv == -1:
 *             raise ValueError, "Write %s to file failed" % file_name
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_file_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = ((ngram_file_type_t)PyInt_AsLong(__pyx_v_format)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rv = ngram_model_write(((struct __pyx_obj_10sphinxbase_NGramModel *)__pyx_v_self)->lm, __pyx_t_1, __pyx_t_2);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":387
 *         cdef int rv
 *         rv = ngram_model_write(self.lm, file_name, format)
 *         if rv == -1:             # <<<<<<<<<<<<<<
 *             raise ValueError, "Write %s to file failed" % file_name
 * 
 */
  __pyx_t_3 = (__pyx_v_rv == -1);
  if (__pyx_t_3) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":388
 *         rv = ngram_model_write(self.lm, file_name, format)
 *         if rv == -1:
 *             raise ValueError, "Write %s to file failed" % file_name             # <<<<<<<<<<<<<<
 * 
 * cdef class NGramIter:
 */
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), __pyx_v_file_name); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_builtin_ValueError, __pyx_t_4, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.NGramModel.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_file_name);
  __Pyx_DECREF(__pyx_v_format);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":397
 *     language model.
 *     """
 *     def __cinit__(self, NGramModel lm, int m):             # <<<<<<<<<<<<<<
 *         self.itor = NULL
 *         self.lm = lm
 */

static int __pyx_pf_10sphinxbase_9NGramIter___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_10sphinxbase_9NGramIter___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_10sphinxbase_NGramModel *__pyx_v_lm = 0;
  int __pyx_v_m;
  int __pyx_r;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lm,&__pyx_n_s__m,0};
  __Pyx_RefNannySetupContext("__cinit__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lm);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__m);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_lm = ((struct __pyx_obj_10sphinxbase_NGramModel *)values[0]);
    __pyx_v_m = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_m == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_lm = ((struct __pyx_obj_10sphinxbase_NGramModel *)PyTuple_GET_ITEM(__pyx_args, 0));
    __pyx_v_m = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_m == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.NGramIter.__cinit__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lm), __pyx_ptype_10sphinxbase_NGramModel, 1, "lm", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":398
 *     """
 *     def __cinit__(self, NGramModel lm, int m):
 *         self.itor = NULL             # <<<<<<<<<<<<<<
 *         self.lm = lm
 *         self.m = m
 */
  ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->itor = NULL;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":399
 *     def __cinit__(self, NGramModel lm, int m):
 *         self.itor = NULL
 *         self.lm = lm             # <<<<<<<<<<<<<<
 *         self.m = m
 *         self.first_item = True
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_lm));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lm));
  __Pyx_GOTREF(((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm));
  ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm = __pyx_v_lm;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":400
 *         self.itor = NULL
 *         self.lm = lm
 *         self.m = m             # <<<<<<<<<<<<<<
 *         self.first_item = True
 * 
 */
  ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->m = __pyx_v_m;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":401
 *         self.lm = lm
 *         self.m = m
 *         self.first_item = True             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->first_item = 1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("sphinxbase.NGramIter.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":403
 *         self.first_item = True
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         self.first_item = True
 *         return self
 */

static PyObject *__pyx_pf_10sphinxbase_9NGramIter___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_9NGramIter___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__iter__");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":404
 * 
 *     def __iter__(self):
 *         self.first_item = True             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->first_item = 1;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":405
 *     def __iter__(self):
 *         self.first_item = True
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef set_iter(NGramIter self, ngram_iter_t *itor):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":407
 *         return self
 * 
 *     cdef set_iter(NGramIter self, ngram_iter_t *itor):             # <<<<<<<<<<<<<<
 *         cdef int32 prob, bowt
 *         cdef int32 *wids
 */

static  PyObject *__pyx_f_10sphinxbase_9NGramIter_set_iter(struct __pyx_obj_10sphinxbase_NGramIter *__pyx_v_self, ngram_iter_t *__pyx_v_itor) {
  __pyx_t_10sphinxbase_int32 __pyx_v_prob;
  __pyx_t_10sphinxbase_int32 __pyx_v_bowt;
  __pyx_t_10sphinxbase_int32 *__pyx_v_wids;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("set_iter");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":411
 *         cdef int32 *wids
 * 
 *         if itor == NULL:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         self.itor = itor
 */
  __pyx_t_1 = (__pyx_v_itor == NULL);
  if (__pyx_t_1) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":412
 * 
 *         if itor == NULL:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         self.itor = itor
 *         if self.first_item:
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":413
 *         if itor == NULL:
 *             raise StopIteration
 *         self.itor = itor             # <<<<<<<<<<<<<<
 *         if self.first_item:
 *             self.first_item = False
 */
  __pyx_v_self->itor = __pyx_v_itor;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":414
 *             raise StopIteration
 *         self.itor = itor
 *         if self.first_item:             # <<<<<<<<<<<<<<
 *             self.first_item = False
 *         wids = ngram_iter_get(itor, &prob, &bowt)
 */
  __pyx_t_2 = __pyx_v_self->first_item;
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":415
 *         self.itor = itor
 *         if self.first_item:
 *             self.first_item = False             # <<<<<<<<<<<<<<
 *         wids = ngram_iter_get(itor, &prob, &bowt)
 *         self.log_prob = logmath_log_to_ln(self.lm.lmath, prob)
 */
    __pyx_v_self->first_item = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":416
 *         if self.first_item:
 *             self.first_item = False
 *         wids = ngram_iter_get(itor, &prob, &bowt)             # <<<<<<<<<<<<<<
 *         self.log_prob = logmath_log_to_ln(self.lm.lmath, prob)
 *         self.log_bowt = logmath_log_to_ln(self.lm.lmath, bowt)
 */
  __pyx_v_wids = ngram_iter_get(__pyx_v_itor, (&__pyx_v_prob), (&__pyx_v_bowt));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":417
 *             self.first_item = False
 *         wids = ngram_iter_get(itor, &prob, &bowt)
 *         self.log_prob = logmath_log_to_ln(self.lm.lmath, prob)             # <<<<<<<<<<<<<<
 *         self.log_bowt = logmath_log_to_ln(self.lm.lmath, bowt)
 *         self.words = []
 */
  __pyx_v_self->log_prob = logmath_log_to_ln(__pyx_v_self->lm->lmath, __pyx_v_prob);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":418
 *         wids = ngram_iter_get(itor, &prob, &bowt)
 *         self.log_prob = logmath_log_to_ln(self.lm.lmath, prob)
 *         self.log_bowt = logmath_log_to_ln(self.lm.lmath, bowt)             # <<<<<<<<<<<<<<
 *         self.words = []
 *         for i in range(0, self.m+1):
 */
  __pyx_v_self->log_bowt = logmath_log_to_ln(__pyx_v_self->lm->lmath, __pyx_v_bowt);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":419
 *         self.log_prob = logmath_log_to_ln(self.lm.lmath, prob)
 *         self.log_bowt = logmath_log_to_ln(self.lm.lmath, bowt)
 *         self.words = []             # <<<<<<<<<<<<<<
 *         for i in range(0, self.m+1):
 *             self.words.append(ngram_word(self.lm.lm, wids[i]))
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __Pyx_GOTREF(__pyx_v_self->words);
  __Pyx_DECREF(__pyx_v_self->words);
  __pyx_v_self->words = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":420
 *         self.log_bowt = logmath_log_to_ln(self.lm.lmath, bowt)
 *         self.words = []
 *         for i in range(0, self.m+1):             # <<<<<<<<<<<<<<
 *             self.words.append(ngram_word(self.lm.lm, wids[i]))
 * 
 */
  __pyx_t_3 = PyInt_FromLong((__pyx_v_self->m + 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_4 = 0; __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5);
  } else {
    __pyx_t_4 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_5))) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_5);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":421
 *         self.words = []
 *         for i in range(0, self.m+1):
 *             self.words.append(ngram_word(self.lm.lm, wids[i]))             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
    __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __Pyx_PyBytes_FromString(ngram_word(__pyx_v_self->lm->lm, (__pyx_v_wids[__pyx_t_6]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_7 = __Pyx_PyObject_Append(__pyx_v_self->words, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("sphinxbase.NGramIter.set_iter");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":423
 *             self.words.append(ngram_word(self.lm.lm, wids[i]))
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         if self.first_item:
 *             self.set_iter(self.itor)
 */

static PyObject *__pyx_pf_10sphinxbase_9NGramIter___next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_9NGramIter___next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__next__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":424
 * 
 *     def __next__(self):
 *         if self.first_item:             # <<<<<<<<<<<<<<
 *             self.set_iter(self.itor)
 *         else:
 */
  __pyx_t_1 = ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->first_item;
  if (__pyx_t_1) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":425
 *     def __next__(self):
 *         if self.first_item:
 *             self.set_iter(self.itor)             # <<<<<<<<<<<<<<
 *         else:
 *             self.set_iter(ngram_iter_next(self.itor))
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_10sphinxbase_NGramIter *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->__pyx_vtab)->set_iter(((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self), ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->itor); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":427
 *             self.set_iter(self.itor)
 *         else:
 *             self.set_iter(ngram_iter_next(self.itor))             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_10sphinxbase_NGramIter *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->__pyx_vtab)->set_iter(((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self), ngram_iter_next(((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->itor)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":428
 *         else:
 *             self.set_iter(ngram_iter_next(self.itor))
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def successors(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("sphinxbase.NGramIter.__next__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":430
 *         return self
 * 
 *     def successors(self):             # <<<<<<<<<<<<<<
 *         """
 *         Get an iterator over N+1-gram successors of an N-gram.
 */

static PyObject *__pyx_pf_10sphinxbase_9NGramIter_successors(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_10sphinxbase_9NGramIter_successors[] = "\n        Get an iterator over N+1-gram successors of an N-gram.\n        ";
static PyObject *__pyx_pf_10sphinxbase_9NGramIter_successors(PyObject *__pyx_v_self, PyObject *unused) {
  struct __pyx_obj_10sphinxbase_NGramIter *__pyx_v_itor;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("successors");
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":435
 *         """
 *         cdef NGramIter itor
 *         itor = NGramIter(self.lm, self.m + 1)             # <<<<<<<<<<<<<<
 *         itor.itor = ngram_iter_successors(self.itor)
 *         return itor
 */
  __pyx_t_1 = PyInt_FromLong((((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->m + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm));
  __Pyx_GIVEREF(((PyObject *)((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->lm));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_10sphinxbase_NGramIter)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_itor));
  __pyx_v_itor = ((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":436
 *         cdef NGramIter itor
 *         itor = NGramIter(self.lm, self.m + 1)
 *         itor.itor = ngram_iter_successors(self.itor)             # <<<<<<<<<<<<<<
 *         return itor
 * 
 */
  __pyx_v_itor->itor = ngram_iter_successors(((struct __pyx_obj_10sphinxbase_NGramIter *)__pyx_v_self)->itor);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":437
 *         itor = NGramIter(self.lm, self.m + 1)
 *         itor.itor = ngram_iter_successors(self.itor)
 *         return itor             # <<<<<<<<<<<<<<
 * 
 * def binstr(str val, int nbits):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_itor));
  __pyx_r = ((PyObject *)__pyx_v_itor);
  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_AddTraceback("sphinxbase.NGramIter.successors");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_itor);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":439
 *         return itor
 * 
 * def binstr(str val, int nbits):             # <<<<<<<<<<<<<<
 *     """
 *     Silly function to format a string as a binary string
 */

static PyObject *__pyx_pf_10sphinxbase_binstr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_binstr[] = "\n    Silly function to format a string as a binary string\n    ";
static PyObject *__pyx_pf_10sphinxbase_binstr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_val = 0;
  int __pyx_v_nbits;
  int __pyx_v_i;
  PyObject *__pyx_v_outstr;
  PyObject *__pyx_v_c;
  PyObject *__pyx_v_cval;
  PyObject *__pyx_v_cnb;
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  long __pyx_t_5;
  int __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__val,&__pyx_n_s__nbits,0};
  __Pyx_RefNannySetupContext("binstr");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__val);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nbits);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("binstr", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "binstr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_val = ((PyObject *)values[0]);
    __pyx_v_nbits = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_nbits == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_val = ((PyObject *)PyTuple_GET_ITEM(__pyx_args, 0));
    __pyx_v_nbits = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_nbits == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("binstr", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.binstr");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_val);
  __pyx_v_outstr = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_c = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_cval = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_cnb = Py_None; __Pyx_INCREF(Py_None);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_val), &PyString_Type, 1, "val", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":444
 *     """
 *     cdef int i
 *     outstr = ""             # <<<<<<<<<<<<<<
 *     for c in val:
 *         cval = ord(c)
 */
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
  __Pyx_DECREF(__pyx_v_outstr);
  __pyx_v_outstr = ((PyObject *)__pyx_kp_s_13);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":445
 *     cdef int i
 *     outstr = ""
 *     for c in val:             # <<<<<<<<<<<<<<
 *         cval = ord(c)
 *         cnb = min(8, nbits)
 */
  __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_val)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  for (;;) {
    {
      __pyx_t_3 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_DECREF(__pyx_v_c);
    __pyx_v_c = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":446
 *     outstr = ""
 *     for c in val:
 *         cval = ord(c)             # <<<<<<<<<<<<<<
 *         cnb = min(8, nbits)
 *         for i in range(0,cnb):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_c);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_c);
    __Pyx_GIVEREF(__pyx_v_c);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ord, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_cval);
    __pyx_v_cval = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":447
 *     for c in val:
 *         cval = ord(c)
 *         cnb = min(8, nbits)             # <<<<<<<<<<<<<<
 *         for i in range(0,cnb):
 *             outstr += "%d" % ((cval & (1 << 7-i)) != 0)
 */
    __pyx_t_4 = PyInt_FromLong(__pyx_v_nbits); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_int_8);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_8);
    __Pyx_GIVEREF(__pyx_int_8);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_builtin_min, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_cnb);
    __pyx_v_cnb = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":448
 *         cval = ord(c)
 *         cnb = min(8, nbits)
 *         for i in range(0,cnb):             # <<<<<<<<<<<<<<
 *             outstr += "%d" % ((cval & (1 << 7-i)) != 0)
 *         nbits -= 8
 */
    __pyx_t_5 = __Pyx_PyInt_AsLong(__pyx_v_cnb); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":449
 *         cnb = min(8, nbits)
 *         for i in range(0,cnb):
 *             outstr += "%d" % ((cval & (1 << 7-i)) != 0)             # <<<<<<<<<<<<<<
 *         nbits -= 8
 *     return outstr
 */
      __pyx_t_4 = PyInt_FromLong((1 << (7 - __pyx_v_i))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyNumber_And(__pyx_v_cval, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_outstr, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_outstr);
      __pyx_v_outstr = __pyx_t_4;
      __pyx_t_4 = 0;
    }

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":450
 *         for i in range(0,cnb):
 *             outstr += "%d" % ((cval & (1 << 7-i)) != 0)
 *         nbits -= 8             # <<<<<<<<<<<<<<
 *     return outstr
 * 
 */
    __pyx_v_nbits -= 8;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":451
 *             outstr += "%d" % ((cval & (1 << 7-i)) != 0)
 *         nbits -= 8
 *     return outstr             # <<<<<<<<<<<<<<
 * 
 * def bincw(int cw, int nbits):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_outstr);
  __pyx_r = __pyx_v_outstr;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.binstr");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_outstr);
  __Pyx_DECREF(__pyx_v_c);
  __Pyx_DECREF(__pyx_v_cval);
  __Pyx_DECREF(__pyx_v_cnb);
  __Pyx_DECREF(__pyx_v_val);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":453
 *     return outstr
 * 
 * def bincw(int cw, int nbits):             # <<<<<<<<<<<<<<
 *     """
 *     Silly function to format an int as a binary string
 */

static PyObject *__pyx_pf_10sphinxbase_bincw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10sphinxbase_bincw[] = "\n    Silly function to format an int as a binary string\n    ";
static PyObject *__pyx_pf_10sphinxbase_bincw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_cw;
  int __pyx_v_nbits;
  int __pyx_v_i;
  PyObject *__pyx_v_outstr;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__cw,&__pyx_n_s__nbits,0};
  __Pyx_RefNannySetupContext("bincw");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cw);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nbits);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("bincw", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "bincw") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_cw = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_cw == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_nbits = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_nbits == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_cw = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_cw == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_nbits = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_nbits == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bincw", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.bincw");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_outstr = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":458
 *     """
 *     cdef int i
 *     outstr = ""             # <<<<<<<<<<<<<<
 *     for i in range(0,nbits):
 *         outstr = "%s" % (cw & 1) + outstr
 */
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
  __Pyx_DECREF(__pyx_v_outstr);
  __pyx_v_outstr = ((PyObject *)__pyx_kp_s_13);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":459
 *     cdef int i
 *     outstr = ""
 *     for i in range(0,nbits):             # <<<<<<<<<<<<<<
 *         outstr = "%s" % (cw & 1) + outstr
 *         cw >>= 1
 */
  __pyx_t_1 = __pyx_v_nbits;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_i = __pyx_t_2;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":460
 *     outstr = ""
 *     for i in range(0,nbits):
 *         outstr = "%s" % (cw & 1) + outstr             # <<<<<<<<<<<<<<
 *         cw >>= 1
 *     return outstr
 */
    __pyx_t_3 = PyInt_FromLong((__pyx_v_cw & 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_15), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_v_outstr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_outstr);
    __pyx_v_outstr = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":461
 *     for i in range(0,nbits):
 *         outstr = "%s" % (cw & 1) + outstr
 *         cw >>= 1             # <<<<<<<<<<<<<<
 *     return outstr
 * 
 */
    __pyx_v_cw >>= 1;
  }

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":462
 *         outstr = "%s" % (cw & 1) + outstr
 *         cw >>= 1
 *     return outstr             # <<<<<<<<<<<<<<
 * 
 * # FIXME: Due to the style of IO in huff_code API this part of the code
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_outstr);
  __pyx_r = __pyx_v_outstr;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.bincw");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_outstr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":482
 *     @type infile: file | str
 *     """
 *     def __init__(self, alphabet=None, infile=None):             # <<<<<<<<<<<<<<
 *         cdef char **symbols
 *         cdef int *frequencies
 */

static int __pyx_pf_10sphinxbase_8HuffCode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_10sphinxbase_8HuffCode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_alphabet = 0;
  PyObject *__pyx_v_infile = 0;
  char **__pyx_v_symbols;
  int *__pyx_v_frequencies;
  int __pyx_v_nsym;
  PyObject *__pyx_v_bogus;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_spam;
  PyObject *__pyx_v_sym;
  PyObject *__pyx_v_freq;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  char *__pyx_t_12;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alphabet,&__pyx_n_s__infile,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphabet);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__infile);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 482; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_alphabet = values[0];
    __pyx_v_infile = values[1];
  } else {
    __pyx_v_alphabet = ((PyObject *)Py_None);
    __pyx_v_infile = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_infile = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_alphabet = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 482; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.HuffCode.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_alphabet);
  __Pyx_INCREF(__pyx_v_infile);
  __pyx_v_bogus = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_spam = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_sym = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_freq = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":487
 *         cdef int nsym
 * 
 *         if alphabet == None and infile == None:             # <<<<<<<<<<<<<<
 *             raise ValueError, "One of alphabet or infile must be passed to constructor"
 *         if alphabet != None and infile != None:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_alphabet, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_infile, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __pyx_t_3;
  } else {
    __pyx_t_4 = __pyx_t_2;
  }
  if (__pyx_t_4) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":488
 * 
 *         if alphabet == None and infile == None:
 *             raise ValueError, "One of alphabet or infile must be passed to constructor"             # <<<<<<<<<<<<<<
 *         if alphabet != None and infile != None:
 *             raise ValueError, "Only one of alphabet or infile must be passed to constructor"
 */
    __Pyx_Raise(__pyx_builtin_ValueError, ((PyObject *)__pyx_kp_s_16), 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":489
 *         if alphabet == None and infile == None:
 *             raise ValueError, "One of alphabet or infile must be passed to constructor"
 *         if alphabet != None and infile != None:             # <<<<<<<<<<<<<<
 *             raise ValueError, "Only one of alphabet or infile must be passed to constructor"
 * 
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_alphabet, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_infile, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  if (__pyx_t_3) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":490
 *             raise ValueError, "One of alphabet or infile must be passed to constructor"
 *         if alphabet != None and infile != None:
 *             raise ValueError, "Only one of alphabet or infile must be passed to constructor"             # <<<<<<<<<<<<<<
 * 
 *         self.fh = None
 */
    __Pyx_Raise(__pyx_builtin_ValueError, ((PyObject *)__pyx_kp_s_17), 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":492
 *             raise ValueError, "Only one of alphabet or infile must be passed to constructor"
 * 
 *         self.fh = None             # <<<<<<<<<<<<<<
 *         if infile:
 *             self.read(infile)
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  __Pyx_DECREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  ((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh = Py_None;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":493
 * 
 *         self.fh = None
 *         if infile:             # <<<<<<<<<<<<<<
 *             self.read(infile)
 *             return
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_infile); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":494
 *         self.fh = None
 *         if infile:
 *             self.read(infile)             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_infile);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_infile);
    __Pyx_GIVEREF(__pyx_v_infile);
    __pyx_t_6 = PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":495
 *         if infile:
 *             self.read(infile)
 *             return             # <<<<<<<<<<<<<<
 * 
 *         nsym = len(alphabet)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":497
 *             return
 * 
 *         nsym = len(alphabet)             # <<<<<<<<<<<<<<
 *         frequencies = <int *>ckd_calloc(nsym, sizeof(int))
 *         symbols = <char **>ckd_calloc(nsym, sizeof(char *))
 */
  __pyx_t_7 = PyObject_Length(__pyx_v_alphabet); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_nsym = __pyx_t_7;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":498
 * 
 *         nsym = len(alphabet)
 *         frequencies = <int *>ckd_calloc(nsym, sizeof(int))             # <<<<<<<<<<<<<<
 *         symbols = <char **>ckd_calloc(nsym, sizeof(char *))
 *         # Need to create separate Python objects for each string,
 */
  __pyx_v_frequencies = ((int *)ckd_calloc(__pyx_v_nsym, (sizeof(int))));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":499
 *         nsym = len(alphabet)
 *         frequencies = <int *>ckd_calloc(nsym, sizeof(int))
 *         symbols = <char **>ckd_calloc(nsym, sizeof(char *))             # <<<<<<<<<<<<<<
 *         # Need to create separate Python objects for each string,
 *         # otherwise we get random duplicates of the codewords...
 */
  __pyx_v_symbols = ((char **)ckd_calloc(__pyx_v_nsym, (sizeof(char *))));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":502
 *         # Need to create separate Python objects for each string,
 *         # otherwise we get random duplicates of the codewords...
 *         bogus = []             # <<<<<<<<<<<<<<
 *         for i, spam in enumerate(alphabet):
 *             sym, freq = spam
 */
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  __Pyx_DECREF(__pyx_v_bogus);
  __pyx_v_bogus = ((PyObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":503
 *         # otherwise we get random duplicates of the codewords...
 *         bogus = []
 *         for i, spam in enumerate(alphabet):             # <<<<<<<<<<<<<<
 *             sym, freq = spam
 *             bogus.append(repr(sym))
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_6 = __pyx_int_0;
  if (PyList_CheckExact(__pyx_v_alphabet) || PyTuple_CheckExact(__pyx_v_alphabet)) {
    __pyx_t_7 = 0; __pyx_t_5 = __pyx_v_alphabet; __Pyx_INCREF(__pyx_t_5);
  } else {
    __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_alphabet); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_5))) {
      if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
      if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
    } else {
      __pyx_t_1 = PyIter_Next(__pyx_t_5);
      if (!__pyx_t_1) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_v_spam);
    __pyx_v_spam = __pyx_t_1;
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_6;
    __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6);
    __pyx_t_6 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":504
 *         bogus = []
 *         for i, spam in enumerate(alphabet):
 *             sym, freq = spam             # <<<<<<<<<<<<<<
 *             bogus.append(repr(sym))
 *             frequencies[i] = freq
 */
    if (PyTuple_CheckExact(__pyx_v_spam) && likely(PyTuple_GET_SIZE(__pyx_v_spam) == 2)) {
      PyObject* tuple = __pyx_v_spam;
      __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
      __pyx_t_8 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_v_sym);
      __pyx_v_sym = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_freq);
      __pyx_v_freq = __pyx_t_8;
      __pyx_t_8 = 0;
    } else {
      __pyx_t_9 = PyObject_GetIter(__pyx_v_spam); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_9, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_9, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_EndUnpack(__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_v_sym);
      __pyx_v_sym = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_freq);
      __pyx_v_freq = __pyx_t_8;
      __pyx_t_8 = 0;
    }

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":505
 *         for i, spam in enumerate(alphabet):
 *             sym, freq = spam
 *             bogus.append(repr(sym))             # <<<<<<<<<<<<<<
 *             frequencies[i] = freq
 *             symbols[i] = bogus[-1]
 */
    __pyx_t_8 = PyObject_Repr(__pyx_v_sym); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = __Pyx_PyObject_Append(__pyx_v_bogus, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":506
 *             sym, freq = spam
 *             bogus.append(repr(sym))
 *             frequencies[i] = freq             # <<<<<<<<<<<<<<
 *             symbols[i] = bogus[-1]
 *         self.hc = huff_code_build_str(symbols, frequencies, nsym)
 */
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_v_freq); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_11 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_11 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_frequencies[__pyx_t_11]) = __pyx_t_10;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":507
 *             bogus.append(repr(sym))
 *             frequencies[i] = freq
 *             symbols[i] = bogus[-1]             # <<<<<<<<<<<<<<
 *         self.hc = huff_code_build_str(symbols, frequencies, nsym)
 *         ckd_free(frequencies)
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_bogus, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_11 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_11 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    (__pyx_v_symbols[__pyx_t_11]) = __pyx_t_12;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":508
 *             frequencies[i] = freq
 *             symbols[i] = bogus[-1]
 *         self.hc = huff_code_build_str(symbols, frequencies, nsym)             # <<<<<<<<<<<<<<
 *         ckd_free(frequencies)
 *         ckd_free(symbols)
 */
  ((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc = huff_code_build_str(__pyx_v_symbols, __pyx_v_frequencies, __pyx_v_nsym);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":509
 *             symbols[i] = bogus[-1]
 *         self.hc = huff_code_build_str(symbols, frequencies, nsym)
 *         ckd_free(frequencies)             # <<<<<<<<<<<<<<
 *         ckd_free(symbols)
 * 
 */
  ckd_free(__pyx_v_frequencies);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":510
 *         self.hc = huff_code_build_str(symbols, frequencies, nsym)
 *         ckd_free(frequencies)
 *         ckd_free(symbols)             # <<<<<<<<<<<<<<
 * 
 *     def read(self, infile):
 */
  ckd_free(__pyx_v_symbols);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("sphinxbase.HuffCode.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_bogus);
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_spam);
  __Pyx_DECREF(__pyx_v_sym);
  __Pyx_DECREF(__pyx_v_freq);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_alphabet);
  __Pyx_DECREF(__pyx_v_infile);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":512
 *         ckd_free(symbols)
 * 
 *     def read(self, infile):             # <<<<<<<<<<<<<<
 *         if not isinstance(infile, file):
 *             infile = file(infile, "rb")
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_read(PyObject *__pyx_v_self, PyObject *__pyx_v_infile); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_read(PyObject *__pyx_v_self, PyObject *__pyx_v_infile) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  huff_code_t *__pyx_t_5;
  __Pyx_RefNannySetupContext("read");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_infile);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":513
 * 
 *     def read(self, infile):
 *         if not isinstance(infile, file):             # <<<<<<<<<<<<<<
 *             infile = file(infile, "rb")
 *         huff_code_free(self.hc)
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_infile, ((PyTypeObject *)((PyObject*)&PyFile_Type))); 
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":514
 *     def read(self, infile):
 *         if not isinstance(infile, file):
 *             infile = file(infile, "rb")             # <<<<<<<<<<<<<<
 *         huff_code_free(self.hc)
 *         self.hc = huff_code_read(PyFile_AsFile(infile))
 */
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_infile);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_infile);
    __Pyx_GIVEREF(__pyx_v_infile);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__rb));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)&PyFile_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_infile);
    __pyx_v_infile = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":515
 *         if not isinstance(infile, file):
 *             infile = file(infile, "rb")
 *         huff_code_free(self.hc)             # <<<<<<<<<<<<<<
 *         self.hc = huff_code_read(PyFile_AsFile(infile))
 * 
 */
  huff_code_free(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":516
 *             infile = file(infile, "rb")
 *         huff_code_free(self.hc)
 *         self.hc = huff_code_read(PyFile_AsFile(infile))             # <<<<<<<<<<<<<<
 * 
 *     def write(self, outfile):
 */
  __pyx_t_5 = huff_code_read(PyFile_AsFile(__pyx_v_infile)); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc = __pyx_t_5;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.HuffCode.read");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_infile);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":518
 *         self.hc = huff_code_read(PyFile_AsFile(infile))
 * 
 *     def write(self, outfile):             # <<<<<<<<<<<<<<
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "wb")
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_write(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_write(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("write");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_outfile);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":519
 * 
 *     def write(self, outfile):
 *         if not isinstance(outfile, file):             # <<<<<<<<<<<<<<
 *             outfile = file(outfile, "wb")
 *         huff_code_write(self.hc, PyFile_AsFile(outfile))
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_outfile, ((PyTypeObject *)((PyObject*)&PyFile_Type))); 
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":520
 *     def write(self, outfile):
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "wb")             # <<<<<<<<<<<<<<
 *         huff_code_write(self.hc, PyFile_AsFile(outfile))
 * 
 */
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_outfile);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_outfile);
    __Pyx_GIVEREF(__pyx_v_outfile);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__wb));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__wb));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__wb));
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)&PyFile_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_outfile);
    __pyx_v_outfile = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":521
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "wb")
 *         huff_code_write(self.hc, PyFile_AsFile(outfile))             # <<<<<<<<<<<<<<
 * 
 *     def dump(self, outfile):
 */
  __pyx_t_5 = huff_code_write(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, PyFile_AsFile(__pyx_v_outfile)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.HuffCode.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_outfile);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":523
 *         huff_code_write(self.hc, PyFile_AsFile(outfile))
 * 
 *     def dump(self, outfile):             # <<<<<<<<<<<<<<
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "w")
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_dump(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_dump(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("dump");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_outfile);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":524
 * 
 *     def dump(self, outfile):
 *         if not isinstance(outfile, file):             # <<<<<<<<<<<<<<
 *             outfile = file(outfile, "w")
 *         huff_code_dump(self.hc, PyFile_AsFile(outfile))
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_outfile, ((PyTypeObject *)((PyObject*)&PyFile_Type))); 
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":525
 *     def dump(self, outfile):
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "w")             # <<<<<<<<<<<<<<
 *         huff_code_dump(self.hc, PyFile_AsFile(outfile))
 * 
 */
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_outfile);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_outfile);
    __Pyx_GIVEREF(__pyx_v_outfile);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__w));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__w));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w));
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)&PyFile_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_outfile);
    __pyx_v_outfile = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":526
 *         if not isinstance(outfile, file):
 *             outfile = file(outfile, "w")
 *         huff_code_dump(self.hc, PyFile_AsFile(outfile))             # <<<<<<<<<<<<<<
 * 
 *     def encode(self, seq):
 */
  __pyx_t_5 = huff_code_dump(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, PyFile_AsFile(__pyx_v_outfile)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.HuffCode.dump");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_outfile);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":528
 *         huff_code_dump(self.hc, PyFile_AsFile(outfile))
 * 
 *     def encode(self, seq):             # <<<<<<<<<<<<<<
 *         """
 *         Encode a sequence of symbols to a byte array, returning that
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_encode(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static char __pyx_doc_10sphinxbase_8HuffCode_encode[] = "\n        Encode a sequence of symbols to a byte array, returning that\n        array and the bit offset of the next codeword in the last\n        byte (i.e. 8 minutes the number of extra zero bits)\n        ";
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_encode(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  unsigned int __pyx_v_cw;
  int __pyx_v_cwlen;
  int __pyx_v_nbits;
  int __pyx_v_nbytes;
  int __pyx_v_offset;
  int __pyx_v_i;
  unsigned char __pyx_v_buf;
  char *__pyx_v_output;
  PyObject *__pyx_v_sym;
  PyObject *__pyx_v_sss;
  PyObject *__pyx_v_outstr;
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("encode");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_seq);
  __pyx_v_sym = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_sss = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_outstr = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":535
 *         """
 *         cdef unsigned int cw
 *         cdef int cwlen, nbits = 0, nbytes, offset, i             # <<<<<<<<<<<<<<
 *         cdef unsigned char buf = 0
 *         cdef char *output
 */
  __pyx_v_nbits = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":536
 *         cdef unsigned int cw
 *         cdef int cwlen, nbits = 0, nbytes, offset, i
 *         cdef unsigned char buf = 0             # <<<<<<<<<<<<<<
 *         cdef char *output
 * 
 */
  __pyx_v_buf = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":539
 *         cdef char *output
 * 
 *         for sym in seq:             # <<<<<<<<<<<<<<
 *             sss = repr(sym)
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 */
  if (PyList_CheckExact(__pyx_v_seq) || PyTuple_CheckExact(__pyx_v_seq)) {
    __pyx_t_1 = 0; __pyx_t_2 = __pyx_v_seq; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_DECREF(__pyx_v_sym);
    __pyx_v_sym = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":540
 * 
 *         for sym in seq:
 *             sss = repr(sym)             # <<<<<<<<<<<<<<
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 *             nbits += cwlen
 */
    __pyx_t_3 = PyObject_Repr(__pyx_v_sym); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_v_sss);
    __pyx_v_sss = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":541
 *         for sym in seq:
 *             sss = repr(sym)
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)             # <<<<<<<<<<<<<<
 *             nbits += cwlen
 *         nbytes = int((nbits + 7) / 8)
 */
    __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_sss); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_cwlen = huff_code_encode_str(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, __pyx_t_4, (&__pyx_v_cw));

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":542
 *             sss = repr(sym)
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 *             nbits += cwlen             # <<<<<<<<<<<<<<
 *         nbytes = int((nbits + 7) / 8)
 *         offset = 0
 */
    __pyx_v_nbits += __pyx_v_cwlen;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":543
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 *             nbits += cwlen
 *         nbytes = int((nbits + 7) / 8)             # <<<<<<<<<<<<<<
 *         offset = 0
 *         output = <char *>PyMem_Malloc(nbytes + 1)
 */
  __pyx_v_nbytes = ((int)__Pyx_div_long((__pyx_v_nbits + 7), 8));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":544
 *             nbits += cwlen
 *         nbytes = int((nbits + 7) / 8)
 *         offset = 0             # <<<<<<<<<<<<<<
 *         output = <char *>PyMem_Malloc(nbytes + 1)
 *         output[nbytes] = 0
 */
  __pyx_v_offset = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":545
 *         nbytes = int((nbits + 7) / 8)
 *         offset = 0
 *         output = <char *>PyMem_Malloc(nbytes + 1)             # <<<<<<<<<<<<<<
 *         output[nbytes] = 0
 *         i = 0
 */
  __pyx_v_output = ((char *)PyMem_Malloc((__pyx_v_nbytes + 1)));

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":546
 *         offset = 0
 *         output = <char *>PyMem_Malloc(nbytes + 1)
 *         output[nbytes] = 0             # <<<<<<<<<<<<<<
 *         i = 0
 *         nbits = 0
 */
  (__pyx_v_output[__pyx_v_nbytes]) = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":547
 *         output = <char *>PyMem_Malloc(nbytes + 1)
 *         output[nbytes] = 0
 *         i = 0             # <<<<<<<<<<<<<<
 *         nbits = 0
 *         for sym in seq:
 */
  __pyx_v_i = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":548
 *         output[nbytes] = 0
 *         i = 0
 *         nbits = 0             # <<<<<<<<<<<<<<
 *         for sym in seq:
 *             sss = repr(sym)
 */
  __pyx_v_nbits = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":549
 *         i = 0
 *         nbits = 0
 *         for sym in seq:             # <<<<<<<<<<<<<<
 *             sss = repr(sym)
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 */
  if (PyList_CheckExact(__pyx_v_seq) || PyTuple_CheckExact(__pyx_v_seq)) {
    __pyx_t_1 = 0; __pyx_t_2 = __pyx_v_seq; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_DECREF(__pyx_v_sym);
    __pyx_v_sym = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":550
 *         nbits = 0
 *         for sym in seq:
 *             sss = repr(sym)             # <<<<<<<<<<<<<<
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)
 *             #print "sym: %s cw: %s buf: %s output: %s" \
 */
    __pyx_t_3 = PyObject_Repr(__pyx_v_sym); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_v_sss);
    __pyx_v_sss = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":551
 *         for sym in seq:
 *             sss = repr(sym)
 *             cwlen = huff_code_encode_str(self.hc, sss, &cw)             # <<<<<<<<<<<<<<
 *             #print "sym: %s cw: %s buf: %s output: %s" \
 *             #      % (sym, bincw(cw, cwlen), bincw(buf >> (8-offset), offset),
 */
    __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_sss); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_cwlen = huff_code_encode_str(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, __pyx_t_4, (&__pyx_v_cw));

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":557
 *             #print "cwlen",cwlen
 *             # Do one byte at a time while full bytes are available
 *             while cwlen >= 8:             # <<<<<<<<<<<<<<
 *                 # Fill low bits of buf with high bits of cw
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)
 */
    while (1) {
      __pyx_t_5 = (__pyx_v_cwlen >= 8);
      if (!__pyx_t_5) break;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":559
 *             while cwlen >= 8:
 *                 # Fill low bits of buf with high bits of cw
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)             # <<<<<<<<<<<<<<
 *                 # Append buf to output
 *                 output[i] = buf
 */
      __pyx_v_buf |= ((__pyx_v_cw >> (__pyx_v_cwlen - (8 - __pyx_v_offset))) & ((1 << (8 - __pyx_v_offset)) - 1));

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":561
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)
 *                 # Append buf to output
 *                 output[i] = buf             # <<<<<<<<<<<<<<
 *                 i += 1
 *                 nbits += 8
 */
      (__pyx_v_output[__pyx_v_i]) = __pyx_v_buf;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":562
 *                 # Append buf to output
 *                 output[i] = buf
 *                 i += 1             # <<<<<<<<<<<<<<
 *                 nbits += 8
 *                 # Fill high bits of buf with low bits of this byte
 */
      __pyx_v_i += 1;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":563
 *                 output[i] = buf
 *                 i += 1
 *                 nbits += 8             # <<<<<<<<<<<<<<
 *                 # Fill high bits of buf with low bits of this byte
 *                 cwlen -= 8
 */
      __pyx_v_nbits += 8;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":565
 *                 nbits += 8
 *                 # Fill high bits of buf with low bits of this byte
 *                 cwlen -= 8             # <<<<<<<<<<<<<<
 *                 buf = (cw >> cwlen) & ((1 << offset) - 1)
 *                 buf <<= (8-offset)
 */
      __pyx_v_cwlen -= 8;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":566
 *                 # Fill high bits of buf with low bits of this byte
 *                 cwlen -= 8
 *                 buf = (cw >> cwlen) & ((1 << offset) - 1)             # <<<<<<<<<<<<<<
 *                 buf <<= (8-offset)
 *                 #print "cwlen",cwlen
 */
      __pyx_v_buf = ((__pyx_v_cw >> __pyx_v_cwlen) & ((1 << __pyx_v_offset) - 1));

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":567
 *                 cwlen -= 8
 *                 buf = (cw >> cwlen) & ((1 << offset) - 1)
 *                 buf <<= (8-offset)             # <<<<<<<<<<<<<<
 *                 #print "cwlen",cwlen
 *             # Now cwlen will be less than 8, but it might still be
 */
      __pyx_v_buf <<= (8 - __pyx_v_offset);
    }

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":571
 *             # Now cwlen will be less than 8, but it might still be
 *             # more than the available space in buf.
 *             if cwlen >= (8 - offset):             # <<<<<<<<<<<<<<
 *                 # Fill low bits of buf with (8-offset) highest bits of cw
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)
 */
    __pyx_t_5 = (__pyx_v_cwlen >= (8 - __pyx_v_offset));
    if (__pyx_t_5) {

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":573
 *             if cwlen >= (8 - offset):
 *                 # Fill low bits of buf with (8-offset) highest bits of cw
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)             # <<<<<<<<<<<<<<
 *                 # Append buf to output
 *                 output[i] = buf
 */
      __pyx_v_buf |= ((__pyx_v_cw >> (__pyx_v_cwlen - (8 - __pyx_v_offset))) & ((1 << (8 - __pyx_v_offset)) - 1));

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":575
 *                 buf |= (cw >> (cwlen - (8 - offset))) & ((1 << (8 - offset)) - 1)
 *                 # Append buf to output
 *                 output[i] = buf             # <<<<<<<<<<<<<<
 *                 i += 1
 *                 nbits += 8
 */
      (__pyx_v_output[__pyx_v_i]) = __pyx_v_buf;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":576
 *                 # Append buf to output
 *                 output[i] = buf
 *                 i += 1             # <<<<<<<<<<<<<<
 *                 nbits += 8
 *                 # cwlen is down to the remaining bits
 */
      __pyx_v_i += 1;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":577
 *                 output[i] = buf
 *                 i += 1
 *                 nbits += 8             # <<<<<<<<<<<<<<
 *                 # cwlen is down to the remaining bits
 *                 cwlen -= (8 - offset)
 */
      __pyx_v_nbits += 8;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":579
 *                 nbits += 8
 *                 # cwlen is down to the remaining bits
 *                 cwlen -= (8 - offset)             # <<<<<<<<<<<<<<
 *                 # Offset is now zero since we just completed and emptied buf
 *                 offset = 0
 */
      __pyx_v_cwlen -= (8 - __pyx_v_offset);

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":581
 *                 cwlen -= (8 - offset)
 *                 # Offset is now zero since we just completed and emptied buf
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 # buf is zero, because we just emptied it without putting stuff in
 *                 buf = 0
 */
      __pyx_v_offset = 0;

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":583
 *                 offset = 0
 *                 # buf is zero, because we just emptied it without putting stuff in
 *                 buf = 0             # <<<<<<<<<<<<<<
 *                 #print "cwlen",cwlen
 *                 # Any remaining  bits will be taken care of below (we hope)
 */
      __pyx_v_buf = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":588
 *             # Add remaining high bits of cw to low bits of buf
 *             #print "cwlen",cwlen
 *             buf |= ((cw & ((1 << cwlen) - 1)) << (8 - offset - cwlen))             # <<<<<<<<<<<<<<
 *             offset += cwlen
 *             #print "after buf: %s output: %s" \
 */
    __pyx_v_buf |= ((__pyx_v_cw & ((1 << __pyx_v_cwlen) - 1)) << ((8 - __pyx_v_offset) - __pyx_v_cwlen));

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":589
 *             #print "cwlen",cwlen
 *             buf |= ((cw & ((1 << cwlen) - 1)) << (8 - offset - cwlen))
 *             offset += cwlen             # <<<<<<<<<<<<<<
 *             #print "after buf: %s output: %s" \
 *             #      % (bincw(buf >> (8-offset), offset), binstr(output, nbits))
 */
    __pyx_v_offset += __pyx_v_cwlen;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":592
 *             #print "after buf: %s output: %s" \
 *             #      % (bincw(buf >> (8-offset), offset), binstr(output, nbits))
 *         if offset > 0:             # <<<<<<<<<<<<<<
 *             # Append buf to output
 *             output[i] = buf
 */
  __pyx_t_5 = (__pyx_v_offset > 0);
  if (__pyx_t_5) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":594
 *         if offset > 0:
 *             # Append buf to output
 *             output[i] = buf             # <<<<<<<<<<<<<<
 *             nbits += offset
 *             i += 1
 */
    (__pyx_v_output[__pyx_v_i]) = __pyx_v_buf;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":595
 *             # Append buf to output
 *             output[i] = buf
 *             nbits += offset             # <<<<<<<<<<<<<<
 *             i += 1
 *         #print "output:", binstr(output, nbits)
 */
    __pyx_v_nbits += __pyx_v_offset;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":596
 *             output[i] = buf
 *             nbits += offset
 *             i += 1             # <<<<<<<<<<<<<<
 *         #print "output:", binstr(output, nbits)
 *         outstr = PyString_FromStringAndSize(output, nbytes)
 */
    __pyx_v_i += 1;
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":598
 *             i += 1
 *         #print "output:", binstr(output, nbits)
 *         outstr = PyString_FromStringAndSize(output, nbytes)             # <<<<<<<<<<<<<<
 *         PyMem_Free(output)
 *         return (outstr, offset)
 */
  __pyx_t_2 = PyString_FromStringAndSize(__pyx_v_output, __pyx_v_nbytes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_outstr);
  __pyx_v_outstr = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":599
 *         #print "output:", binstr(output, nbits)
 *         outstr = PyString_FromStringAndSize(output, nbytes)
 *         PyMem_Free(output)             # <<<<<<<<<<<<<<
 *         return (outstr, offset)
 * 
 */
  PyMem_Free(__pyx_v_output);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":600
 *         outstr = PyString_FromStringAndSize(output, nbytes)
 *         PyMem_Free(output)
 *         return (outstr, offset)             # <<<<<<<<<<<<<<
 * 
 *     def decode(self, data):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_outstr);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_outstr);
  __Pyx_GIVEREF(__pyx_v_outstr);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__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_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("sphinxbase.HuffCode.encode");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_sym);
  __Pyx_DECREF(__pyx_v_sss);
  __Pyx_DECREF(__pyx_v_outstr);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":602
 *         return (outstr, offset)
 * 
 *     def decode(self, data):             # <<<<<<<<<<<<<<
 *         """
 *         Decode a sequence of symbols from a string, returning the
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_decode(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
static char __pyx_doc_10sphinxbase_8HuffCode_decode[] = "\n        Decode a sequence of symbols from a string, returning the\n        sequence and the bit offset of the next codeword in the last\n        byte (i.e. 8 minutes the number of remaining bits)\n        ";
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_decode(PyObject *__pyx_v_self, PyObject *__pyx_v_data) {
  int __pyx_v_offset;
  char *__pyx_v_dptr;
  char *__pyx_v_strval;
  size_t __pyx_v_dlen;
  PyObject *__pyx_v_output;
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  char *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("decode");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_data);
  __pyx_v_output = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":613
 *         cdef size_t dlen
 * 
 *         dlen = len(data)             # <<<<<<<<<<<<<<
 *         offset = 0
 *         dptr = data
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dlen = __pyx_t_1;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":614
 * 
 *         dlen = len(data)
 *         offset = 0             # <<<<<<<<<<<<<<
 *         dptr = data
 *         output = []
 */
  __pyx_v_offset = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":615
 *         dlen = len(data)
 *         offset = 0
 *         dptr = data             # <<<<<<<<<<<<<<
 *         output = []
 *         while True:
 */
  __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dptr = __pyx_t_2;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":616
 *         offset = 0
 *         dptr = data
 *         output = []             # <<<<<<<<<<<<<<
 *         while True:
 *             strval = huff_code_decode_str(self.hc, &dptr, &dlen, &offset)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_DECREF(__pyx_v_output);
  __pyx_v_output = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":617
 *         dptr = data
 *         output = []
 *         while True:             # <<<<<<<<<<<<<<
 *             strval = huff_code_decode_str(self.hc, &dptr, &dlen, &offset)
 *             if strval == NULL:
 */
  while (1) {
    __pyx_t_4 = 1;
    if (!__pyx_t_4) break;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":618
 *         output = []
 *         while True:
 *             strval = huff_code_decode_str(self.hc, &dptr, &dlen, &offset)             # <<<<<<<<<<<<<<
 *             if strval == NULL:
 *                 break
 */
    __pyx_v_strval = huff_code_decode_str(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, (&__pyx_v_dptr), (&__pyx_v_dlen), (&__pyx_v_offset));

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":619
 *         while True:
 *             strval = huff_code_decode_str(self.hc, &dptr, &dlen, &offset)
 *             if strval == NULL:             # <<<<<<<<<<<<<<
 *                 break
 *             output.append(strval)
 */
    __pyx_t_4 = (__pyx_v_strval == NULL);
    if (__pyx_t_4) {

      /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":620
 *             strval = huff_code_decode_str(self.hc, &dptr, &dlen, &offset)
 *             if strval == NULL:
 *                 break             # <<<<<<<<<<<<<<
 *             output.append(strval)
 *         if dlen > 1:
 */
      goto __pyx_L6_break;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":621
 *             if strval == NULL:
 *                 break
 *             output.append(strval)             # <<<<<<<<<<<<<<
 *         if dlen > 1:
 *             raise ValueError, "Invalid data at position %d" % (len(data) - dlen)
 */
    __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_strval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_output, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_L6_break:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":622
 *                 break
 *             output.append(strval)
 *         if dlen > 1:             # <<<<<<<<<<<<<<
 *             raise ValueError, "Invalid data at position %d" % (len(data) - dlen)
 *         return (output, offset)
 */
  __pyx_t_4 = (__pyx_v_dlen > 1);
  if (__pyx_t_4) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":623
 *             output.append(strval)
 *         if dlen > 1:
 *             raise ValueError, "Invalid data at position %d" % (len(data) - dlen)             # <<<<<<<<<<<<<<
 *         return (output, offset)
 * 
 */
    __pyx_t_1 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyInt_FromSize_t((__pyx_t_1 - __pyx_v_dlen)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_builtin_ValueError, __pyx_t_3, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":624
 *         if dlen > 1:
 *             raise ValueError, "Invalid data at position %d" % (len(data) - dlen)
 *         return (output, offset)             # <<<<<<<<<<<<<<
 * 
 *     def attach(self, fh, char *mode):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_output);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_output);
  __Pyx_GIVEREF(__pyx_v_output);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("sphinxbase.HuffCode.decode");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_output);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":626
 *         return (output, offset)
 * 
 *     def attach(self, fh, char *mode):             # <<<<<<<<<<<<<<
 *         if not isinstance(fh, file):
 *             fh = file(fh, mode)
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_attach(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_attach(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_fh = 0;
  char *__pyx_v_mode;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fh,&__pyx_n_s__mode,0};
  __Pyx_RefNannySetupContext("attach");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fh);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("attach", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "attach") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_fh = values[0];
    __pyx_v_mode = __Pyx_PyBytes_AsString(values[1]); if (unlikely((!__pyx_v_mode) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_fh = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_mode = __Pyx_PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((!__pyx_v_mode) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("attach", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("sphinxbase.HuffCode.attach");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_fh);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":627
 * 
 *     def attach(self, fh, char *mode):
 *         if not isinstance(fh, file):             # <<<<<<<<<<<<<<
 *             fh = file(fh, mode)
 *         self.fh = fh
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_fh, ((PyTypeObject *)((PyObject*)&PyFile_Type))); 
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":628
 *     def attach(self, fh, char *mode):
 *         if not isinstance(fh, file):
 *             fh = file(fh, mode)             # <<<<<<<<<<<<<<
 *         self.fh = fh
 *         huff_code_attach(self.hc, PyFile_AsFile(fh), mode)
 */
    __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_mode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_fh);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fh);
    __Pyx_GIVEREF(__pyx_v_fh);
    PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyFile_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_fh);
    __pyx_v_fh = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":629
 *         if not isinstance(fh, file):
 *             fh = file(fh, mode)
 *         self.fh = fh             # <<<<<<<<<<<<<<
 *         huff_code_attach(self.hc, PyFile_AsFile(fh), mode)
 * 
 */
  __Pyx_INCREF(__pyx_v_fh);
  __Pyx_GIVEREF(__pyx_v_fh);
  __Pyx_GOTREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  __Pyx_DECREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  ((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh = __pyx_v_fh;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":630
 *             fh = file(fh, mode)
 *         self.fh = fh
 *         huff_code_attach(self.hc, PyFile_AsFile(fh), mode)             # <<<<<<<<<<<<<<
 * 
 *     def detach(self):
 */
  huff_code_attach(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, PyFile_AsFile(__pyx_v_fh), __pyx_v_mode);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.HuffCode.attach");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_fh);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":632
 *         huff_code_attach(self.hc, PyFile_AsFile(fh), mode)
 * 
 *     def detach(self):             # <<<<<<<<<<<<<<
 *         huff_code_detach(self.hc)
 *         self.fh = None
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_detach(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_detach(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("detach");

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":633
 * 
 *     def detach(self):
 *         huff_code_detach(self.hc)             # <<<<<<<<<<<<<<
 *         self.fh = None
 * 
 */
  huff_code_detach(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":634
 *     def detach(self):
 *         huff_code_detach(self.hc)
 *         self.fh = None             # <<<<<<<<<<<<<<
 * 
 *     def encode_to_file(self, seq):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  __Pyx_DECREF(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh);
  ((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh = Py_None;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":636
 *         self.fh = None
 * 
 *     def encode_to_file(self, seq):             # <<<<<<<<<<<<<<
 *         if self.fh == None:
 *             raise RuntimeError, "No file is attached"
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_encode_to_file(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_encode_to_file(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  PyObject *__pyx_v_sym;
  PyObject *__pyx_v_strsym;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  __Pyx_RefNannySetupContext("encode_to_file");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_seq);
  __pyx_v_sym = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_strsym = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":637
 * 
 *     def encode_to_file(self, seq):
 *         if self.fh == None:             # <<<<<<<<<<<<<<
 *             raise RuntimeError, "No file is attached"
 *         for sym in seq:
 */
  __pyx_t_1 = PyObject_RichCompare(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":638
 *     def encode_to_file(self, seq):
 *         if self.fh == None:
 *             raise RuntimeError, "No file is attached"             # <<<<<<<<<<<<<<
 *         for sym in seq:
 *             strsym = repr(sym)
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_19), 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":639
 *         if self.fh == None:
 *             raise RuntimeError, "No file is attached"
 *         for sym in seq:             # <<<<<<<<<<<<<<
 *             strsym = repr(sym)
 *             huff_code_encode_str(self.hc, strsym, NULL)
 */
  if (PyList_CheckExact(__pyx_v_seq) || PyTuple_CheckExact(__pyx_v_seq)) {
    __pyx_t_3 = 0; __pyx_t_1 = __pyx_v_seq; __Pyx_INCREF(__pyx_t_1);
  } else {
    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_seq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_1))) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else {
      __pyx_t_4 = PyIter_Next(__pyx_t_1);
      if (!__pyx_t_4) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_DECREF(__pyx_v_sym);
    __pyx_v_sym = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":640
 *             raise RuntimeError, "No file is attached"
 *         for sym in seq:
 *             strsym = repr(sym)             # <<<<<<<<<<<<<<
 *             huff_code_encode_str(self.hc, strsym, NULL)
 * 
 */
    __pyx_t_4 = PyObject_Repr(__pyx_v_sym); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_v_strsym);
    __pyx_v_strsym = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":641
 *         for sym in seq:
 *             strsym = repr(sym)
 *             huff_code_encode_str(self.hc, strsym, NULL)             # <<<<<<<<<<<<<<
 * 
 *     def decode_from_file(self):
 */
    __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_strsym); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    huff_code_encode_str(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, __pyx_t_5, NULL);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("sphinxbase.HuffCode.encode_to_file");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_sym);
  __Pyx_DECREF(__pyx_v_strsym);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":643
 *             huff_code_encode_str(self.hc, strsym, NULL)
 * 
 *     def decode_from_file(self):             # <<<<<<<<<<<<<<
 *         cdef char *sym
 *         if self.fh == None:
 */

static PyObject *__pyx_pf_10sphinxbase_8HuffCode_decode_from_file(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_10sphinxbase_8HuffCode_decode_from_file(PyObject *__pyx_v_self, PyObject *unused) {
  char *__pyx_v_sym;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("decode_from_file");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":645
 *     def decode_from_file(self):
 *         cdef char *sym
 *         if self.fh == None:             # <<<<<<<<<<<<<<
 *             raise RuntimeError, "No file is attached"
 *         sym = huff_code_decode_str(self.hc, NULL, NULL, NULL)
 */
  __pyx_t_1 = PyObject_RichCompare(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":646
 *         cdef char *sym
 *         if self.fh == None:
 *             raise RuntimeError, "No file is attached"             # <<<<<<<<<<<<<<
 *         sym = huff_code_decode_str(self.hc, NULL, NULL, NULL)
 *         if sym == NULL:
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_19), 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":647
 *         if self.fh == None:
 *             raise RuntimeError, "No file is attached"
 *         sym = huff_code_decode_str(self.hc, NULL, NULL, NULL)             # <<<<<<<<<<<<<<
 *         if sym == NULL:
 *             return None
 */
  __pyx_v_sym = huff_code_decode_str(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc, NULL, NULL, NULL);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":648
 *             raise RuntimeError, "No file is attached"
 *         sym = huff_code_decode_str(self.hc, NULL, NULL, NULL)
 *         if sym == NULL:             # <<<<<<<<<<<<<<
 *             return None
 *         else:
 */
  __pyx_t_2 = (__pyx_v_sym == NULL);
  if (__pyx_t_2) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":649
 *         sym = huff_code_decode_str(self.hc, NULL, NULL, NULL)
 *         if sym == NULL:
 *             return None             # <<<<<<<<<<<<<<
 *         else:
 *             return sym
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":651
 *             return None
 *         else:
 *             return sym             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_sym); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_r = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("sphinxbase.HuffCode.decode_from_file");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":653
 *             return sym
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.fh:
 *             self.detach()
 */

static void __pyx_pf_10sphinxbase_8HuffCode___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_10sphinxbase_8HuffCode___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":654
 * 
 *     def __dealloc__(self):
 *         if self.fh:             # <<<<<<<<<<<<<<
 *             self.detach()
 *         huff_code_free(self.hc)
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->fh); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":655
 *     def __dealloc__(self):
 *         if self.fh:
 *             self.detach()             # <<<<<<<<<<<<<<
 *         huff_code_free(self.hc)
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__detach); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __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_3); __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":656
 *         if self.fh:
 *             self.detach()
 *         huff_code_free(self.hc)             # <<<<<<<<<<<<<<
 */
  huff_code_free(((struct __pyx_obj_10sphinxbase_HuffCode *)__pyx_v_self)->hc);

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("sphinxbase.HuffCode.__dealloc__");
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
}
static struct __pyx_vtabstruct_10sphinxbase_NGramModel __pyx_vtable_10sphinxbase_NGramModel;

static PyObject *__pyx_tp_new_10sphinxbase_NGramModel(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10sphinxbase_NGramModel *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10sphinxbase_NGramModel *)o);
  p->__pyx_vtab = __pyx_vtabptr_10sphinxbase_NGramModel;
  return o;
}

static void __pyx_tp_dealloc_10sphinxbase_NGramModel(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_10sphinxbase_10NGramModel___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_10sphinxbase_NGramModel[] = {
  {__Pyx_NAMESTR("apply_weights"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_apply_weights, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_apply_weights)},
  {__Pyx_NAMESTR("get_size"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_get_size, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_get_size)},
  {__Pyx_NAMESTR("get_counts"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_get_counts, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_get_counts)},
  {__Pyx_NAMESTR("unknown_wid"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_unknown_wid, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_unknown_wid)},
  {__Pyx_NAMESTR("zero"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_zero, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_zero)},
  {__Pyx_NAMESTR("wid"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_wid, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_wid)},
  {__Pyx_NAMESTR("word"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_word, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_word)},
  {__Pyx_NAMESTR("score"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_score, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_score)},
  {__Pyx_NAMESTR("prob"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_prob, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_prob)},
  {__Pyx_NAMESTR("mgrams"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_mgrams, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_mgrams)},
  {__Pyx_NAMESTR("ngram"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_ngram, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_10NGramModel_ngram)},
  {__Pyx_NAMESTR("add_word"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_add_word, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("recode"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_recode, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("casefold"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_casefold, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_10sphinxbase_10NGramModel_write, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_10sphinxbase_NGramModel[] = {
  {(char *)"lw", T_FLOAT, offsetof(struct __pyx_obj_10sphinxbase_NGramModel, lw), READONLY, 0},
  {(char *)"wip", T_FLOAT, offsetof(struct __pyx_obj_10sphinxbase_NGramModel, wip), READONLY, 0},
  {(char *)"uw", T_FLOAT, offsetof(struct __pyx_obj_10sphinxbase_NGramModel, uw), READONLY, 0},
  {0, 0, 0, 0, 0}
};

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

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

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

static PyBufferProcs __pyx_tp_as_buffer_NGramModel = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_10sphinxbase_NGramModel = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("sphinxbase.NGramModel"), /*tp_name*/
  sizeof(struct __pyx_obj_10sphinxbase_NGramModel), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10sphinxbase_NGramModel, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_NGramModel, /*tp_as_number*/
  &__pyx_tp_as_sequence_NGramModel, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_NGramModel, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_NGramModel, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\n    N-Gram language model class.\n\n    This class provides access to N-Gram language models stored on\n    disk.  These can be in ARPABO text format or Sphinx DMP format.\n    Methods are provided for scoring N-Grams based on the model\n    and looking up words in the model.\n\n    @param file: Path to an N-Gram model file.\n    @type file: string\n    @param lw: Language weight to apply to model probabilities.\n    @type lw: float\n    @param wip: Word insertion penalty to add to model probabilities\n    @type wip: float\n    @param uw: Weight to give unigrams when interpolating with uniform distribution.\n    @type uw: float\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10sphinxbase_NGramModel, /*tp_methods*/
  __pyx_members_10sphinxbase_NGramModel, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_10sphinxbase_10NGramModel___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10sphinxbase_NGramModel, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10sphinxbase_LogMath(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  return o;
}

static void __pyx_tp_dealloc_10sphinxbase_LogMath(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_10sphinxbase_7LogMath___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_10sphinxbase_LogMath[] = {
  {__Pyx_NAMESTR("get_zero"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_get_zero, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_get_zero)},
  {__Pyx_NAMESTR("add"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_add, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_add)},
  {__Pyx_NAMESTR("log"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_log, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_log)},
  {__Pyx_NAMESTR("exp"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_exp, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_exp)},
  {__Pyx_NAMESTR("log_to_ln"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_log_to_ln, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_log_to_ln)},
  {__Pyx_NAMESTR("log_to_log10"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_log_to_log10, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_log_to_log10)},
  {__Pyx_NAMESTR("ln_to_log"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_ln_to_log, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_ln_to_log)},
  {__Pyx_NAMESTR("log10_to_log"), (PyCFunction)__pyx_pf_10sphinxbase_7LogMath_log10_to_log, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_7LogMath_log10_to_log)},
  {0, 0, 0, 0}
};

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

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

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

static PyBufferProcs __pyx_tp_as_buffer_LogMath = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_10sphinxbase_LogMath = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("sphinxbase.LogMath"), /*tp_name*/
  sizeof(struct __pyx_obj_10sphinxbase_LogMath), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10sphinxbase_LogMath, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_LogMath, /*tp_as_number*/
  &__pyx_tp_as_sequence_LogMath, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_LogMath, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_LogMath, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\n    Log-space math class.\n    \n    This class provides fast logarithmic math functions in base\n    1.000+epsilon, useful for fixed point speech recognition.\n\n    @param base: The base B in which computation is to be done.\n    @type base: float\n    @param shift: Log values are shifted right by this many bits.\n    @type shift: int\n    @param use_table Whether to use an add table or not\n    @type use_table: bool\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10sphinxbase_LogMath, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_10sphinxbase_7LogMath___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10sphinxbase_LogMath, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_10sphinxbase_NGramIter __pyx_vtable_10sphinxbase_NGramIter;

static PyObject *__pyx_tp_new_10sphinxbase_NGramIter(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10sphinxbase_NGramIter *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10sphinxbase_NGramIter *)o);
  p->__pyx_vtab = __pyx_vtabptr_10sphinxbase_NGramIter;
  p->lm = ((struct __pyx_obj_10sphinxbase_NGramModel *)Py_None); Py_INCREF(Py_None);
  p->words = Py_None; Py_INCREF(Py_None);
  if (__pyx_pf_10sphinxbase_9NGramIter___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10sphinxbase_NGramIter(PyObject *o) {
  struct __pyx_obj_10sphinxbase_NGramIter *p = (struct __pyx_obj_10sphinxbase_NGramIter *)o;
  Py_XDECREF(((PyObject *)p->lm));
  Py_XDECREF(p->words);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10sphinxbase_NGramIter(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10sphinxbase_NGramIter *p = (struct __pyx_obj_10sphinxbase_NGramIter *)o;
  if (p->lm) {
    e = (*v)(((PyObject*)p->lm), a); if (e) return e;
  }
  if (p->words) {
    e = (*v)(p->words, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10sphinxbase_NGramIter(PyObject *o) {
  struct __pyx_obj_10sphinxbase_NGramIter *p = (struct __pyx_obj_10sphinxbase_NGramIter *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->lm);
  p->lm = ((struct __pyx_obj_10sphinxbase_NGramModel *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->words);
  p->words = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static struct PyMethodDef __pyx_methods_10sphinxbase_NGramIter[] = {
  {__Pyx_NAMESTR("__iter__"), (PyCFunction)__pyx_pf_10sphinxbase_9NGramIter___iter__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_10sphinxbase_9NGramIter___next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("successors"), (PyCFunction)__pyx_pf_10sphinxbase_9NGramIter_successors, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_9NGramIter_successors)},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_10sphinxbase_NGramIter[] = {
  {(char *)"log_prob", T_FLOAT, offsetof(struct __pyx_obj_10sphinxbase_NGramIter, log_prob), READONLY, 0},
  {(char *)"log_bowt", T_FLOAT, offsetof(struct __pyx_obj_10sphinxbase_NGramIter, log_bowt), READONLY, 0},
  {(char *)"words", T_OBJECT, offsetof(struct __pyx_obj_10sphinxbase_NGramIter, words), READONLY, 0},
  {0, 0, 0, 0, 0}
};

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

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

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

static PyBufferProcs __pyx_tp_as_buffer_NGramIter = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_10sphinxbase_NGramIter = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("sphinxbase.NGramIter"), /*tp_name*/
  sizeof(struct __pyx_obj_10sphinxbase_NGramIter), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10sphinxbase_NGramIter, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_NGramIter, /*tp_as_number*/
  &__pyx_tp_as_sequence_NGramIter, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_NGramIter, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_NGramIter, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("\n    N-Gram language model iterator class.\n\n    This class provides access to the individual N-grams stored in a\n    language model.\n    "), /*tp_doc*/
  __pyx_tp_traverse_10sphinxbase_NGramIter, /*tp_traverse*/
  __pyx_tp_clear_10sphinxbase_NGramIter, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pf_10sphinxbase_9NGramIter___iter__, /*tp_iter*/
  __pyx_pf_10sphinxbase_9NGramIter___next__, /*tp_iternext*/
  __pyx_methods_10sphinxbase_NGramIter, /*tp_methods*/
  __pyx_members_10sphinxbase_NGramIter, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10sphinxbase_NGramIter, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10sphinxbase_HuffCode(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10sphinxbase_HuffCode *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10sphinxbase_HuffCode *)o);
  p->fh = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_10sphinxbase_HuffCode(PyObject *o) {
  struct __pyx_obj_10sphinxbase_HuffCode *p = (struct __pyx_obj_10sphinxbase_HuffCode *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_10sphinxbase_8HuffCode___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->fh);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10sphinxbase_HuffCode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10sphinxbase_HuffCode *p = (struct __pyx_obj_10sphinxbase_HuffCode *)o;
  if (p->fh) {
    e = (*v)(p->fh, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10sphinxbase_HuffCode(PyObject *o) {
  struct __pyx_obj_10sphinxbase_HuffCode *p = (struct __pyx_obj_10sphinxbase_HuffCode *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->fh);
  p->fh = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static struct PyMethodDef __pyx_methods_10sphinxbase_HuffCode[] = {
  {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_read, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_write, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("dump"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_dump, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("encode"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_encode, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_8HuffCode_encode)},
  {__Pyx_NAMESTR("decode"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_decode, METH_O, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_8HuffCode_decode)},
  {__Pyx_NAMESTR("attach"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_attach, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("detach"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_detach, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("encode_to_file"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_encode_to_file, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("decode_from_file"), (PyCFunction)__pyx_pf_10sphinxbase_8HuffCode_decode_from_file, METH_NOARGS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

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

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

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

static PyBufferProcs __pyx_tp_as_buffer_HuffCode = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_10sphinxbase_HuffCode = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("sphinxbase.HuffCode"), /*tp_name*/
  sizeof(struct __pyx_obj_10sphinxbase_HuffCode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10sphinxbase_HuffCode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_HuffCode, /*tp_as_number*/
  &__pyx_tp_as_sequence_HuffCode, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_HuffCode, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_HuffCode, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("\n    Huffman coding class.\n\n    You can either construct a Huffman code from an alphabet of\n    symbols with frequencies, or read one from a file.  Either the\n    alphabet or infile argument (but not both) must be passed to the\n    constructor.\n\n    @param alphabet: Alphabet of (symbol, frequency) pairs\n    @type alphabet: [(str, int)]\n    @param infile: File handle or filename to read from\n    @type infile: file | str\n    "), /*tp_doc*/
  __pyx_tp_traverse_10sphinxbase_HuffCode, /*tp_traverse*/
  __pyx_tp_clear_10sphinxbase_HuffCode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10sphinxbase_HuffCode, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_10sphinxbase_8HuffCode___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10sphinxbase_HuffCode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("binstr"), (PyCFunction)__pyx_pf_10sphinxbase_binstr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_binstr)},
  {__Pyx_NAMESTR("bincw"), (PyCFunction)__pyx_pf_10sphinxbase_bincw, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_10sphinxbase_bincw)},
  {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("sphinxbase"),
    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_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__ARPA, __pyx_k__ARPA, sizeof(__pyx_k__ARPA), 0, 0, 1, 1},
  {&__pyx_n_s__AUTO, __pyx_k__AUTO, sizeof(__pyx_k__AUTO), 0, 0, 1, 1},
  {&__pyx_n_s__DMP, __pyx_k__DMP, sizeof(__pyx_k__DMP), 0, 0, 1, 1},
  {&__pyx_n_s__LOWER, __pyx_k__LOWER, sizeof(__pyx_k__LOWER), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
  {&__pyx_n_s__UPPER, __pyx_k__UPPER, sizeof(__pyx_k__UPPER), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1},
  {&__pyx_n_s__alphabet, __pyx_k__alphabet, sizeof(__pyx_k__alphabet), 0, 0, 1, 1},
  {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1},
  {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1},
  {&__pyx_n_s__cw, __pyx_k__cw, sizeof(__pyx_k__cw), 0, 0, 1, 1},
  {&__pyx_n_s__detach, __pyx_k__detach, sizeof(__pyx_k__detach), 0, 0, 1, 1},
  {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1},
  {&__pyx_n_s__fh, __pyx_k__fh, sizeof(__pyx_k__fh), 0, 0, 1, 1},
  {&__pyx_n_s__file, __pyx_k__file, sizeof(__pyx_k__file), 0, 0, 1, 1},
  {&__pyx_n_s__file_name, __pyx_k__file_name, sizeof(__pyx_k__file_name), 0, 0, 1, 1},
  {&__pyx_n_s__first_item, __pyx_k__first_item, sizeof(__pyx_k__first_item), 0, 0, 1, 1},
  {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1},
  {&__pyx_n_s__frum, __pyx_k__frum, sizeof(__pyx_k__frum), 0, 0, 1, 1},
  {&__pyx_n_s__hc, __pyx_k__hc, sizeof(__pyx_k__hc), 0, 0, 1, 1},
  {&__pyx_n_s__infile, __pyx_k__infile, sizeof(__pyx_k__infile), 0, 0, 1, 1},
  {&__pyx_n_s__itor, __pyx_k__itor, sizeof(__pyx_k__itor), 0, 0, 1, 1},
  {&__pyx_n_s__lm, __pyx_k__lm, sizeof(__pyx_k__lm), 0, 0, 1, 1},
  {&__pyx_n_s__lmath, __pyx_k__lmath, sizeof(__pyx_k__lmath), 0, 0, 1, 1},
  {&__pyx_n_s__lmctl, __pyx_k__lmctl, sizeof(__pyx_k__lmctl), 0, 0, 1, 1},
  {&__pyx_n_s__log_bowt, __pyx_k__log_bowt, sizeof(__pyx_k__log_bowt), 0, 0, 1, 1},
  {&__pyx_n_s__log_prob, __pyx_k__log_prob, sizeof(__pyx_k__log_prob), 0, 0, 1, 1},
  {&__pyx_n_s__lw, __pyx_k__lw, sizeof(__pyx_k__lw), 0, 0, 1, 1},
  {&__pyx_n_s__m, __pyx_k__m, sizeof(__pyx_k__m), 0, 0, 1, 1},
  {&__pyx_n_s__min, __pyx_k__min, sizeof(__pyx_k__min), 0, 0, 1, 1},
  {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
  {&__pyx_n_s__nbits, __pyx_k__nbits, sizeof(__pyx_k__nbits), 0, 0, 1, 1},
  {&__pyx_n_s__ord, __pyx_k__ord, sizeof(__pyx_k__ord), 0, 0, 1, 1},
  {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
  {&__pyx_n_s__rb, __pyx_k__rb, sizeof(__pyx_k__rb), 0, 0, 1, 1},
  {&__pyx_n_s__read, __pyx_k__read, sizeof(__pyx_k__read), 0, 0, 1, 1},
  {&__pyx_n_s__set_iter, __pyx_k__set_iter, sizeof(__pyx_k__set_iter), 0, 0, 1, 1},
  {&__pyx_n_s__shift, __pyx_k__shift, sizeof(__pyx_k__shift), 0, 0, 1, 1},
  {&__pyx_n_s__too, __pyx_k__too, sizeof(__pyx_k__too), 0, 0, 1, 1},
  {&__pyx_n_s__use_table, __pyx_k__use_table, sizeof(__pyx_k__use_table), 0, 0, 1, 1},
  {&__pyx_n_s__uw, __pyx_k__uw, sizeof(__pyx_k__uw), 0, 0, 1, 1},
  {&__pyx_n_s__val, __pyx_k__val, sizeof(__pyx_k__val), 0, 0, 1, 1},
  {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1},
  {&__pyx_n_s__wb, __pyx_k__wb, sizeof(__pyx_k__wb), 0, 0, 1, 1},
  {&__pyx_n_s__weight, __pyx_k__weight, sizeof(__pyx_k__weight), 0, 0, 1, 1},
  {&__pyx_n_s__wip, __pyx_k__wip, sizeof(__pyx_k__wip), 0, 0, 1, 1},
  {&__pyx_n_s__word, __pyx_k__word, sizeof(__pyx_k__word), 0, 0, 1, 1},
  {&__pyx_n_s__words, __pyx_k__words, sizeof(__pyx_k__words), 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 = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ord = __Pyx_GetName(__pyx_b, __pyx_n_s__ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_min = __Pyx_GetName(__pyx_b, __pyx_n_s__min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __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;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__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 initsphinxbase(void); /*proto*/
PyMODINIT_FUNC initsphinxbase(void)
#else
PyMODINIT_FUNC PyInit_sphinxbase(void); /*proto*/
PyMODINIT_FUNC PyInit_sphinxbase(void)
#endif
{
  PyObject *__pyx_t_1 = 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_sphinxbase(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("sphinxbase"), __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_sphinxbase) {
    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 ---*/
  __pyx_vtabptr_10sphinxbase_NGramModel = &__pyx_vtable_10sphinxbase_NGramModel;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_10sphinxbase_NGramModel.set_lm = (PyObject *(*)(struct __pyx_obj_10sphinxbase_NGramModel *, ngram_model_t *))__pyx_f_10sphinxbase_10NGramModel_set_lm;
  __pyx_vtable_10sphinxbase_NGramModel.set_lmath = (PyObject *(*)(struct __pyx_obj_10sphinxbase_NGramModel *, logmath_t *))__pyx_f_10sphinxbase_10NGramModel_set_lmath;
  #else
  *(void(**)(void))&__pyx_vtable_10sphinxbase_NGramModel.set_lm = (void(*)(void))__pyx_f_10sphinxbase_10NGramModel_set_lm;
  *(void(**)(void))&__pyx_vtable_10sphinxbase_NGramModel.set_lmath = (void(*)(void))__pyx_f_10sphinxbase_10NGramModel_set_lmath;
  #endif
  if (PyType_Ready(&__pyx_type_10sphinxbase_NGramModel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_10sphinxbase_NGramModel.tp_dict, __pyx_vtabptr_10sphinxbase_NGramModel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "NGramModel", (PyObject *)&__pyx_type_10sphinxbase_NGramModel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10sphinxbase_NGramModel = &__pyx_type_10sphinxbase_NGramModel;
  if (PyType_Ready(&__pyx_type_10sphinxbase_LogMath) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "LogMath", (PyObject *)&__pyx_type_10sphinxbase_LogMath) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10sphinxbase_LogMath = &__pyx_type_10sphinxbase_LogMath;
  __pyx_vtabptr_10sphinxbase_NGramIter = &__pyx_vtable_10sphinxbase_NGramIter;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_10sphinxbase_NGramIter.set_iter = (PyObject *(*)(struct __pyx_obj_10sphinxbase_NGramIter *, ngram_iter_t *))__pyx_f_10sphinxbase_9NGramIter_set_iter;
  #else
  *(void(**)(void))&__pyx_vtable_10sphinxbase_NGramIter.set_iter = (void(*)(void))__pyx_f_10sphinxbase_9NGramIter_set_iter;
  #endif
  if (PyType_Ready(&__pyx_type_10sphinxbase_NGramIter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_10sphinxbase_NGramIter.tp_dict, __pyx_vtabptr_10sphinxbase_NGramIter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "NGramIter", (PyObject *)&__pyx_type_10sphinxbase_NGramIter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10sphinxbase_NGramIter = &__pyx_type_10sphinxbase_NGramIter;
  if (PyType_Ready(&__pyx_type_10sphinxbase_HuffCode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "HuffCode", (PyObject *)&__pyx_type_10sphinxbase_HuffCode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10sphinxbase_HuffCode = &__pyx_type_10sphinxbase_HuffCode;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":24
 *     @type use_table: bool
 *     """
 *     def __init__(self, base=1.0001, shift=0, use_table=1):             # <<<<<<<<<<<<<<
 *         self.lmath = logmath_init(base, shift, use_table)
 * 
 */
  __pyx_t_1 = PyFloat_FromDouble(1.0001); 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);
  __pyx_k_1 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":122
 * 
 * # Unfortunately, Cython doesn't actually export enums to Python...
 * AUTO = NGRAM_AUTO             # <<<<<<<<<<<<<<
 * ARPA = NGRAM_ARPA
 * DMP = NGRAM_DMP
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_AUTO); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__AUTO, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":123
 * # Unfortunately, Cython doesn't actually export enums to Python...
 * AUTO = NGRAM_AUTO
 * ARPA = NGRAM_ARPA             # <<<<<<<<<<<<<<
 * DMP = NGRAM_DMP
 * UPPER = NGRAM_UPPER
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_ARPA); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ARPA, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":124
 * AUTO = NGRAM_AUTO
 * ARPA = NGRAM_ARPA
 * DMP = NGRAM_DMP             # <<<<<<<<<<<<<<
 * UPPER = NGRAM_UPPER
 * LOWER = NGRAM_LOWER
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_DMP); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DMP, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":125
 * ARPA = NGRAM_ARPA
 * DMP = NGRAM_DMP
 * UPPER = NGRAM_UPPER             # <<<<<<<<<<<<<<
 * LOWER = NGRAM_LOWER
 * 
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_UPPER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__UPPER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":126
 * DMP = NGRAM_DMP
 * UPPER = NGRAM_UPPER
 * LOWER = NGRAM_LOWER             # <<<<<<<<<<<<<<
 * 
 * cdef class NGramModel:
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_LOWER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__LOWER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":146
 *     @type uw: float
 *     """
 *     def __init__(self, file=None, lw=1.0, wip=1.0, uw=1.0, lmctl=None):             # <<<<<<<<<<<<<<
 *         self.lmath = logmath_init(1.0001, 0, 0)
 *         if file:
 */
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __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;
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_3 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_4 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":176
 *         ngram_model_free(self.lm)
 * 
 *     def apply_weights(self, lw=1.0, wip=1.0, uw=1.0):             # <<<<<<<<<<<<<<
 *         """
 *         Change the language model weights applied in L{score}.
 */
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_5 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_6 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_7 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":369
 *         return itor
 * 
 *     def add_word(self, word, weight=1.0):             # <<<<<<<<<<<<<<
 *         return ngram_model_add_word(self.lm, word, weight)
 * 
 */
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_8 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pyx":384
 *             raise ValueError, "Casefolding failed"
 * 
 *     def write(self, file_name, format=NGRAM_AUTO):             # <<<<<<<<<<<<<<
 *         cdef int rv
 *         rv = ngram_model_write(self.lm, file_name, format)
 */
  __pyx_t_1 = PyInt_FromLong(NGRAM_AUTO); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_11 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/nshmyrev/projects/cmusphinx-dist/t/sphinxbase/python/sphinxbase.pxd":1
 * # Copyright (c) 2008 Carnegie Mellon University. All rights             # <<<<<<<<<<<<<<
 * # reserved.
 * #
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  if (__pyx_m) {
    __Pyx_AddTraceback("init sphinxbase");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init sphinxbase");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "sphinxbase.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;
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
        #if PY_VERSION_HEX < 0x02050000
                 "need more than %d value%s to unpack", (int)index,
        #else
                 "need more than %zd value%s to unpack", index,
        #endif
                 (index == 1) ? "" : "s");
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) {
    PyErr_SetString(PyExc_ValueError, "too many values to unpack");
}

static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
    PyObject *item;
    if (!(item = PyIter_Next(iter))) {
        if (!PyErr_Occurred()) {
            __Pyx_RaiseNeedMoreValuesError(index);
        }
    }
    return item;
}

static int __Pyx_EndUnpack(PyObject *iter) {
    PyObject *item;
    if ((item = PyIter_Next(iter))) {
        Py_DECREF(item);
        __Pyx_RaiseTooManyValuesError();
        return -1;
    }
    else if (!PyErr_Occurred())
        return 0;
    else
        return -1;
}


static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

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


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

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static 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 int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX < 0x03010000
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#else
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

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