/* Generated by Pyrex 0.9.4.1 on Tue Mar 20 17:58:18 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 "Scientific/arrayobject.h"


typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
static int __Pyx_PrintItem(PyObject *); /*proto*/
static int __Pyx_PrintNewline(void); /*proto*/
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static void __Pyx_ReRaise(void); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
static PyObject *__Pyx_GetExcValue(void); /*proto*/
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
static void __Pyx_WriteUnraisable(char *name); /*proto*/
static void __Pyx_AddTraceback(char *funcname); /*proto*/
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

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

/* Declarations from Scientific_affinitypropagation */

static PyTypeObject *__pyx_ptype_30Scientific_affinitypropagation_ArrayType = 0;

/* Implementation of Scientific_affinitypropagation */


static PyObject *__pyx_n_N;
static PyObject *__pyx_n__affinityPropagation;
static PyObject *__pyx_n_Scientific;

static PyObject *__pyx_n_zeros;
static PyObject *__pyx_n_nsimilarities;
static PyObject *__pyx_n_Float;
static PyObject *__pyx_n_r_update_indices;
static PyObject *__pyx_n_maximum;
static PyObject *__pyx_n_take;
static PyObject *__pyx_n_a_update_indices_1;
static PyObject *__pyx_n_nitems;
static PyObject *__pyx_n_a_update_indices_2;
static PyObject *__pyx_n_minimum;

static PyObject *__pyx_f_30Scientific_affinitypropagation__affinityPropagation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_30Scientific_affinitypropagation__affinityPropagation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dataset = 0;
  PyArrayObject *__pyx_v_s = 0;
  PyArrayObject *__pyx_v_a = 0;
  PyArrayObject *__pyx_v_r = 0;
  float __pyx_v_damping;
  PyArrayObject *__pyx_v_as;
  PyArrayObject *__pyx_v_r_new;
  PyArrayObject *__pyx_v_a_new;
  PyArrayObject *__pyx_v_rpos;
  PyArrayObject *__pyx_v_ind_array;
  long (*__pyx_v_ind);
  double (*__pyx_v_dptr);
  double __pyx_v_v;
  int __pyx_v_i;
  int __pyx_v_j;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  long __pyx_5;
  int __pyx_6;
  int __pyx_7;
  static char *__pyx_argnames[] = {"dataset","s","a","r","damping",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOOf", __pyx_argnames, &__pyx_v_dataset, &__pyx_v_s, &__pyx_v_a, &__pyx_v_r, &__pyx_v_damping)) return 0;
  Py_INCREF(__pyx_v_dataset);
  Py_INCREF(__pyx_v_s);
  Py_INCREF(__pyx_v_a);
  Py_INCREF(__pyx_v_r);
  __pyx_v_as = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  __pyx_v_r_new = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  __pyx_v_a_new = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  __pyx_v_rpos = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  __pyx_v_ind_array = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_s), __pyx_ptype_30Scientific_affinitypropagation_ArrayType, 1, "s")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_30Scientific_affinitypropagation_ArrayType, 1, "a")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; goto __pyx_L1;}
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_r), __pyx_ptype_30Scientific_affinitypropagation_ArrayType, 1, "r")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;}

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":25 */
  __pyx_1 = PyNumber_Add(((PyObject *)__pyx_v_a), ((PyObject *)__pyx_v_s)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_as));
  __pyx_v_as = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":26 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_N); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_zeros); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nsimilarities); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_N); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  __pyx_4 = PyObject_GetAttr(__pyx_1, __pyx_n_Float); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_4);
  __pyx_3 = 0;
  __pyx_4 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_2, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_r_new));
  __pyx_v_r_new = ((PyArrayObject *)__pyx_3);
  __pyx_3 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":27 */
  __pyx_4 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nsimilarities); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;}
  __pyx_5 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_5; ++__pyx_v_i) {

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":28 */
    __pyx_2 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_r_update_indices); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
    __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
    __pyx_3 = PyObject_GetItem(__pyx_2, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_ind_array));
    __pyx_v_ind_array = ((PyArrayObject *)__pyx_3);
    __pyx_3 = 0;

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":29 */
    __pyx_v_ind = ((long (*))__pyx_v_ind_array->data);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":30 */
    __pyx_v_dptr = ((double (*))__pyx_v_as->data);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":31 */
    __pyx_v_v = (__pyx_v_dptr[(__pyx_v_ind[0])]);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":32 */
    __pyx_6 = (__pyx_v_ind_array->dimensions[0]);
    for (__pyx_v_j = 1; __pyx_v_j < __pyx_6; ++__pyx_v_j) {

      /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":33 */
      __pyx_7 = ((__pyx_v_dptr[(__pyx_v_ind[__pyx_v_j])]) > __pyx_v_v);
      if (__pyx_7) {

        /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":34 */
        __pyx_v_v = (__pyx_v_dptr[(__pyx_v_ind[__pyx_v_j])]);
        goto __pyx_L6;
      }
      __pyx_L6:;
      __pyx_L4:;
    }
    __pyx_L5:;

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":35 */
    __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    __pyx_2 = PyObject_GetItem(((PyObject *)__pyx_v_s), __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_1 = PyFloat_FromDouble(__pyx_v_v); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    __pyx_3 = PyNumber_Subtract(__pyx_2, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    if (PyObject_SetItem(((PyObject *)__pyx_v_r_new), __pyx_4, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_L2:;
  }
  __pyx_L3:;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":36 */
  __pyx_2 = PyFloat_FromDouble(__pyx_v_damping); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  __pyx_1 = PyNumber_Multiply(__pyx_2, ((PyObject *)__pyx_v_r)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyFloat_FromDouble((1 - __pyx_v_damping)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  __pyx_3 = PyNumber_Multiply(__pyx_4, ((PyObject *)__pyx_v_r_new)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  __pyx_2 = PyNumber_Add(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_r));
  __pyx_v_r = ((PyArrayObject *)__pyx_2);
  __pyx_2 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":38 */
  __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_n_N); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  __pyx_1 = PyObject_GetAttr(__pyx_4, __pyx_n_maximum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  __pyx_3 = PyFloat_FromDouble(0.); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
  Py_INCREF(((PyObject *)__pyx_v_r));
  PyTuple_SET_ITEM(__pyx_2, 1, ((PyObject *)__pyx_v_r));
  __pyx_3 = 0;
  __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (!__Pyx_TypeTest(__pyx_4, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_rpos));
  __pyx_v_rpos = ((PyArrayObject *)__pyx_4);
  __pyx_4 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":39 */
  __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n_N); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  __pyx_1 = PyObject_GetAttr(__pyx_3, __pyx_n_take); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_2 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_a_update_indices_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_INCREF(((PyObject *)__pyx_v_r));
  PyTuple_SET_ITEM(__pyx_4, 0, ((PyObject *)__pyx_v_r));
  PyTuple_SET_ITEM(__pyx_4, 1, __pyx_2);
  __pyx_2 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_a_new));
  __pyx_v_a_new = ((PyArrayObject *)__pyx_3);
  __pyx_3 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":40 */
  __pyx_2 = PyFloat_FromDouble(0.); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  __pyx_1 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nitems); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  __pyx_4 = PyNumber_Negative(__pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_7 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (PySequence_SetSlice(((PyObject *)__pyx_v_a_new), __pyx_7, 0x7fffffff, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":41 */
  __pyx_3 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nsimilarities); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;}
  __pyx_5 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_5; ++__pyx_v_i) {

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":42 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_a_update_indices_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; goto __pyx_L1;}
    __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; goto __pyx_L1;}
    __pyx_2 = PyObject_GetItem(__pyx_1, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; goto __pyx_L1;}
    Py_DECREF(((PyObject *)__pyx_v_ind_array));
    __pyx_v_ind_array = ((PyArrayObject *)__pyx_2);
    __pyx_2 = 0;

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":43 */
    __pyx_v_ind = ((long (*))__pyx_v_ind_array->data);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":44 */
    __pyx_v_dptr = ((double (*))__pyx_v_rpos->data);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":45 */
    __pyx_v_v = (__pyx_v_dptr[(__pyx_v_ind[0])]);

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":46 */
    __pyx_6 = (__pyx_v_ind_array->dimensions[0]);
    for (__pyx_v_j = 1; __pyx_v_j < __pyx_6; ++__pyx_v_j) {

      /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":47 */
      __pyx_v_v = (__pyx_v_v + (__pyx_v_dptr[(__pyx_v_ind[__pyx_v_j])]));
      __pyx_L9:;
    }
    __pyx_L10:;

    /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":48 */
    __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    __pyx_1 = PyObject_GetItem(((PyObject *)__pyx_v_a_new), __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_4 = PyFloat_FromDouble(__pyx_v_v); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    __pyx_2 = PyNumber_Add(__pyx_1, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    if (PyObject_SetItem(((PyObject *)__pyx_v_a_new), __pyx_3, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_L7:;
  }
  __pyx_L8:;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":49 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_N); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_4 = PyObject_GetAttr(__pyx_1, __pyx_n_minimum); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = PyFloat_FromDouble(0.); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nitems); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_1 = PyNumber_Negative(__pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_7 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_2 = PySequence_GetSlice(((PyObject *)__pyx_v_a_new), 0, __pyx_7); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_2);
  __pyx_3 = 0;
  __pyx_2 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_2 = PyObject_GetAttr(__pyx_v_dataset, __pyx_n_nitems); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_4 = PyNumber_Negative(__pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_6 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (PySequence_SetSlice(((PyObject *)__pyx_v_a_new), 0, __pyx_6, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":50 */
  __pyx_1 = PyFloat_FromDouble(__pyx_v_damping); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  __pyx_2 = PyNumber_Multiply(__pyx_1, ((PyObject *)__pyx_v_a)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_4 = PyFloat_FromDouble((1 - __pyx_v_damping)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  __pyx_3 = PyNumber_Multiply(__pyx_4, ((PyObject *)__pyx_v_a_new)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  __pyx_1 = PyNumber_Add(__pyx_2, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_30Scientific_affinitypropagation_ArrayType)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_a));
  __pyx_v_a = ((PyArrayObject *)__pyx_1);
  __pyx_1 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":52 */
  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
  Py_INCREF(((PyObject *)__pyx_v_a));
  PyTuple_SET_ITEM(__pyx_4, 0, ((PyObject *)__pyx_v_a));
  Py_INCREF(((PyObject *)__pyx_v_r));
  PyTuple_SET_ITEM(__pyx_4, 1, ((PyObject *)__pyx_v_r));
  __pyx_r = __pyx_4;
  __pyx_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("Scientific_affinitypropagation._affinityPropagation");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_as);
  Py_DECREF(__pyx_v_r_new);
  Py_DECREF(__pyx_v_a_new);
  Py_DECREF(__pyx_v_rpos);
  Py_DECREF(__pyx_v_ind_array);
  Py_DECREF(__pyx_v_dataset);
  Py_DECREF(__pyx_v_s);
  Py_DECREF(__pyx_v_a);
  Py_DECREF(__pyx_v_r);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n_Float, "Float"},
  {&__pyx_n_N, "N"},
  {&__pyx_n_Scientific, "Scientific"},
  {&__pyx_n__affinityPropagation, "_affinityPropagation"},
  {&__pyx_n_a_update_indices_1, "a_update_indices_1"},
  {&__pyx_n_a_update_indices_2, "a_update_indices_2"},
  {&__pyx_n_maximum, "maximum"},
  {&__pyx_n_minimum, "minimum"},
  {&__pyx_n_nitems, "nitems"},
  {&__pyx_n_nsimilarities, "nsimilarities"},
  {&__pyx_n_r_update_indices, "r_update_indices"},
  {&__pyx_n_take, "take"},
  {&__pyx_n_zeros, "zeros"},
  {0, 0}
};

static struct PyMethodDef __pyx_methods[] = {
  {"_affinityPropagation", (PyCFunction)__pyx_f_30Scientific_affinitypropagation__affinityPropagation, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC initScientific_affinitypropagation(void); /*proto*/
PyMODINIT_FUNC initScientific_affinitypropagation(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("Scientific_affinitypropagation", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;};
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;};
  __pyx_ptype_30Scientific_affinitypropagation_ArrayType = __Pyx_ImportType("Scientific.N", "ArrayType", sizeof(PyArrayObject)); if (!__pyx_ptype_30Scientific_affinitypropagation_ArrayType) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; goto __pyx_L1;}

  /* "Include/Scientific/numeric.pxi":36 */
  import_array();

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":10 */
  __pyx_1 = PyList_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  Py_INCREF(__pyx_n_N);
  PyList_SET_ITEM(__pyx_1, 0, __pyx_n_N);
  __pyx_2 = __Pyx_Import(__pyx_n_Scientific, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_N); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_N, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/Users/hinsen/Programs/ScientificPython/main/Src/Scientific_affinitypropagation.pyx":12 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("Scientific_affinitypropagation");
}

static char *__pyx_filenames[] = {
  "Scientific_affinitypropagation.pyx",
  "numeric.pxi",
};

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

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 PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

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

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