/* Generated by Pyrex 0.9.5.1a on Mon Sep  3 23:07:16 2007 */

#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
__PYX_EXTERN_C double pow(double, double);
#include "numpy/arrayobject.h"
#include "fwd_bwd.h"


typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
static char **__pyx_f;

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

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

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

static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/

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

static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/

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

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

/* Declarations from c_numpy */

static PyTypeObject *__pyx_ptype_7c_numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_7c_numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_7c_numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_7c_numpy_broadcast = 0;

/* Declarations from fwd_bwd */


/* Declarations from _fwd_bwd */

static double (__pyx_f_8_fwd_bwd_call_inner(inner_funcptr ,PyArrayObject *,PyArrayObject *,PyArrayObject *,PyArrayObject *,PyArrayObject *,npy_intp )); /*proto*/


/* Implementation of _fwd_bwd */

static char (__pyx_k1[]) = "$Revision: 41 $";

static PyObject *__pyx_n___version__;
static PyObject *__pyx_n_fwd;
static PyObject *__pyx_n_bwd;

static PyObject *__pyx_k1p;

static double __pyx_f_8_fwd_bwd_call_inner(inner_funcptr __pyx_v_func,PyArrayObject *__pyx_v_f,PyArrayObject *__pyx_v_x,PyArrayObject *__pyx_v_a,PyArrayObject *__pyx_v_e,PyArrayObject *__pyx_v_c,npy_intp __pyx_v_f_row_start) {
  PyArrayObject *f_contiguous;
  PyArrayObject *a_contiguous;
  PyArrayObject *e_contiguous;
  PyArrayObject *x_contiguous;
  PyArrayObject *c_contiguous;
  double (*f_data);
  double (*a_data);
  double (*e_data);
  npy_intp (*x_data);
  npy_intp (*c_data);
  npy_intp f_rows;
  npy_intp a_cols;
  npy_intp e_cols;
  npy_intp f_cols;
  npy_intp c_cols;
  double __pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_f);
  Py_INCREF(__pyx_v_x);
  Py_INCREF(__pyx_v_a);
  Py_INCREF(__pyx_v_e);
  Py_INCREF(__pyx_v_c);
  f_contiguous = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  a_contiguous = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  e_contiguous = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  x_contiguous = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  c_contiguous = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":24 */
  __pyx_1 = PyArray_GETCONTIGUOUS(__pyx_v_f); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; goto __pyx_L1;}
  Py_DECREF(((PyObject *)f_contiguous));
  f_contiguous = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":25 */
  f_rows = (f_contiguous->dimensions[0]);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":26 */
  f_cols = (f_contiguous->dimensions[1]);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":27 */
  f_data = ((double (*))PyArray_DATA(f_contiguous));

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":30 */
  __pyx_1 = PyArray_GETCONTIGUOUS(__pyx_v_x); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;}
  Py_DECREF(((PyObject *)x_contiguous));
  x_contiguous = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":31 */
  x_data = ((npy_intp (*))PyArray_DATA(x_contiguous));

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":34 */
  __pyx_1 = PyArray_GETCONTIGUOUS(__pyx_v_a); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
  Py_DECREF(((PyObject *)a_contiguous));
  a_contiguous = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":35 */
  a_cols = (a_contiguous->dimensions[1]);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":36 */
  a_data = ((double (*))PyArray_DATA(a_contiguous));

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":39 */
  __pyx_1 = PyArray_GETCONTIGUOUS(__pyx_v_e); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_DECREF(((PyObject *)e_contiguous));
  e_contiguous = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":40 */
  e_cols = (e_contiguous->dimensions[1]);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":41 */
  e_data = ((double (*))PyArray_DATA(e_contiguous));

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":44 */
  __pyx_1 = PyArray_GETCONTIGUOUS(__pyx_v_c); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
  Py_DECREF(((PyObject *)c_contiguous));
  c_contiguous = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":45 */
  c_cols = (c_contiguous->dimensions[1]);

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":46 */
  c_data = ((npy_intp (*))PyArray_DATA(c_contiguous));

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":48 */
  __pyx_r = __pyx_v_func(f_data,x_data,a_data,e_data,c_data,f_rows,f_cols,a_cols,e_cols,c_cols,__pyx_v_f_row_start);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_WriteUnraisable("_fwd_bwd.call_inner");
  __pyx_L0:;
  Py_DECREF(f_contiguous);
  Py_DECREF(a_contiguous);
  Py_DECREF(e_contiguous);
  Py_DECREF(x_contiguous);
  Py_DECREF(c_contiguous);
  Py_DECREF(__pyx_v_f);
  Py_DECREF(__pyx_v_x);
  Py_DECREF(__pyx_v_a);
  Py_DECREF(__pyx_v_e);
  Py_DECREF(__pyx_v_c);
  return __pyx_r;
}

static PyObject *__pyx_f_8_fwd_bwd_fwd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8_fwd_bwd_fwd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_f = 0;
  PyArrayObject *__pyx_v_x = 0;
  PyArrayObject *__pyx_v_a = 0;
  PyArrayObject *__pyx_v_e = 0;
  PyArrayObject *__pyx_v_c = 0;
  int __pyx_v_f_row_start;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"f","x","a","e","c","f_row_start",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOOOi", __pyx_argnames, &__pyx_v_f, &__pyx_v_x, &__pyx_v_a, &__pyx_v_e, &__pyx_v_c, &__pyx_v_f_row_start)) return 0;
  Py_INCREF(__pyx_v_f);
  Py_INCREF(__pyx_v_x);
  Py_INCREF(__pyx_v_a);
  Py_INCREF(__pyx_v_e);
  Py_INCREF(__pyx_v_c);
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_7c_numpy_ndarray, 1, "f")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_7c_numpy_ndarray, 1, "x")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_7c_numpy_ndarray, 1, "a")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_7c_numpy_ndarray, 1, "e")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_7c_numpy_ndarray, 1, "c")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":51 */
  __pyx_1 = PyFloat_FromDouble(__pyx_f_8_fwd_bwd_call_inner(fwd_inner,__pyx_v_f,__pyx_v_x,__pyx_v_a,__pyx_v_e,__pyx_v_c,__pyx_v_f_row_start)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("_fwd_bwd.fwd");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_f);
  Py_DECREF(__pyx_v_x);
  Py_DECREF(__pyx_v_a);
  Py_DECREF(__pyx_v_e);
  Py_DECREF(__pyx_v_c);
  return __pyx_r;
}

static PyObject *__pyx_f_8_fwd_bwd_bwd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8_fwd_bwd_bwd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_b = 0;
  PyArrayObject *__pyx_v_x = 0;
  PyArrayObject *__pyx_v_a = 0;
  PyArrayObject *__pyx_v_e = 0;
  PyArrayObject *__pyx_v_c = 0;
  int __pyx_v_b_row_start;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"b","x","a","e","c","b_row_start",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOOOi", __pyx_argnames, &__pyx_v_b, &__pyx_v_x, &__pyx_v_a, &__pyx_v_e, &__pyx_v_c, &__pyx_v_b_row_start)) return 0;
  Py_INCREF(__pyx_v_b);
  Py_INCREF(__pyx_v_x);
  Py_INCREF(__pyx_v_a);
  Py_INCREF(__pyx_v_e);
  Py_INCREF(__pyx_v_c);
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_b), __pyx_ptype_7c_numpy_ndarray, 1, "b")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_7c_numpy_ndarray, 1, "x")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_7c_numpy_ndarray, 1, "a")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_7c_numpy_ndarray, 1, "e")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_7c_numpy_ndarray, 1, "c")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":54 */
  __pyx_1 = PyFloat_FromDouble(__pyx_f_8_fwd_bwd_call_inner(bwd_inner,__pyx_v_b,__pyx_v_x,__pyx_v_a,__pyx_v_e,__pyx_v_c,__pyx_v_b_row_start)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("_fwd_bwd.bwd");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_b);
  Py_DECREF(__pyx_v_x);
  Py_DECREF(__pyx_v_a);
  Py_DECREF(__pyx_v_e);
  Py_DECREF(__pyx_v_c);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n___version__, "__version__"},
  {&__pyx_n_bwd, "bwd"},
  {&__pyx_n_fwd, "fwd"},
  {0, 0}
};

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)},
  {0, 0, 0}
};

static struct PyMethodDef __pyx_methods[] = {
  {"fwd", (PyCFunction)__pyx_f_8_fwd_bwd_fwd, METH_VARARGS|METH_KEYWORDS, 0},
  {"bwd", (PyCFunction)__pyx_f_8_fwd_bwd_bwd, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC init_fwd_bwd(void); /*proto*/
PyMODINIT_FUNC init_fwd_bwd(void) {
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_fwd_bwd", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  __pyx_ptype_7c_numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (!__pyx_ptype_7c_numpy_dtype) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; goto __pyx_L1;}
  __pyx_ptype_7c_numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (!__pyx_ptype_7c_numpy_ndarray) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 83; goto __pyx_L1;}
  __pyx_ptype_7c_numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject)); if (!__pyx_ptype_7c_numpy_flatiter) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
  __pyx_ptype_7c_numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject)); if (!__pyx_ptype_7c_numpy_broadcast) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":1 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___version__, __pyx_k1p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":8 */
  import_array();

  /* "/lustre/work1/ensembl/mh5/src/sci-util/sunflower/trunk/src/_fwd_bwd.pyx":53 */
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("_fwd_bwd");
}

static char *__pyx_filenames[] = {
  "_fwd_bwd.pyx",
  "c_numpy.pxd",
};

/* Runtime support code */

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

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

static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (obj == Py_None || PyObject_TypeCheck(obj, type))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
        obj->ob_type->tp_name, type->tp_name);
    return 0;
}

static void __Pyx_WriteUnraisable(char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    PyErr_Fetch(&old_exc, &old_val, &old_tb);
    ctx = PyString_FromString(name);
    PyErr_Restore(old_exc, old_val, old_tb);
    if (!ctx)
        ctx = Py_None;
    PyErr_WriteUnraisable(ctx);
}

static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
    while (t->p) {
        *t->p = PyString_InternFromString(t->s);
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, 
    long size) 
{
    PyObject *py_module_name = 0;
    PyObject *py_class_name = 0;
    PyObject *py_name_list = 0;
    PyObject *py_module = 0;
    PyObject *result = 0;
    
    py_module_name = PyString_FromString(module_name);
    if (!py_module_name)
        goto bad;
    py_class_name = PyString_FromString(class_name);
    if (!py_class_name)
        goto bad;
    py_name_list = PyList_New(1);
    if (!py_name_list)
        goto bad;
    Py_INCREF(py_class_name);
    if (PyList_SetItem(py_name_list, 0, py_class_name) < 0)
        goto bad;
    py_module = __Pyx_Import(py_module_name, py_name_list);
    if (!py_module)
        goto bad;
    result = PyObject_GetAttr(py_module, py_class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError, 
            "%s.%s is not a type object",
            module_name, class_name);
        goto bad;
    }
    if (((PyTypeObject *)result)->tp_basicsize != size) {
        PyErr_Format(PyExc_ValueError, 
            "%s.%s does not appear to be the correct type object",
            module_name, class_name);
        goto bad;
    }
    goto done;
bad:
    Py_XDECREF(result);
    result = 0;
done:
    Py_XDECREF(py_module_name);
    Py_XDECREF(py_class_name);
    Py_XDECREF(py_name_list);
    return (PyTypeObject *)result;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunction(__import__, "OOOO",
        name, global_dict, empty_dict, list);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

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

static void __Pyx_AddTraceback(char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_tuple = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    
    py_srcfile = PyString_FromString(__pyx_filename);
    if (!py_srcfile) goto bad;
    py_funcname = PyString_FromString(funcname);
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    empty_tuple = PyTuple_New(0);
    if (!empty_tuple) goto bad;
    empty_string = PyString_FromString("");
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        empty_tuple,  /*PyObject *consts,*/
        empty_tuple,  /*PyObject *names,*/
        empty_tuple,  /*PyObject *varnames,*/
        empty_tuple,  /*PyObject *freevars,*/
        empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*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(empty_tuple);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
