Cython: kmeans.pyx

Generated by Cython 0.23.4

Yellow lines hint at Python interaction.
Click on a line that starts with a "`+`" to see the C code that Cython generated for it.

Raw output: kmeans.c

    +001: #cython: boundscheck=False

      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     002: #cython: cdivision=True

     003: # kmeans.pyx

     004: # Contact: Jacob Schreiber ( jmschreiber91@gmail.com )

     005:

     006: from libc.stdlib cimport calloc

     007: from libc.stdlib cimport free

     008: from libc.string cimport memset

     009: from libc.string cimport memcpy

     010: from libc.math cimport log10 as clog10

     011:

     012: from .base cimport Model

     013:

    +014: import json

      __pyx_t_1 = __Pyx_Import(__pyx_n_s_json, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_json, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +015: import numpy

      __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     016: cimport numpy

     017:

     018:

     019: DEF NEGINF = float("-inf")

     020: DEF INF = float("inf")

     021:

     022:

    +023: def initialize_centroids(numpy.ndarray X, numpy.ndarray weights, int k,

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_1initialize_centroids(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static char __pyx_doc_11pomegranate_6kmeans_initialize_centroids[] = "Initialize the centroids for kmeans given a dataset.\n\n\tThis function will take in a dataset and return the centroids found using\n\tsome method. This is the initialization step of kmeans.\n\n\tParameters\n\t----------\n\tX : numpy.ndarray, shape=(n_samples, n_dim)\n\t\tThe dataset to identify centroids in.\n\n\tweights : numpy.ndarray, shape=(n_samples,)\n\t\tThe weights associated with each of the samples.\n\n\tk : int\n\t\tThe number of centroids to extract.\n\n\tinit : str, one of 'first-k', 'random', 'kmeans++'\n\t\t'first-k' : use the first k samples as the centroids\n\t\t'random' : randomly select k samples as the centroids\n\t\t'kmeans++' : use the kmeans++ initialization algorithm, which\n\t\t\titeratively selects the next centroid randomly, but weighted\n\t\t\tbased on distance to nearest centroid, to be likely to choose\n\t\t\tgood initializations\n\n\tReturns\n\t-------\n\n\t";
    static PyMethodDef __pyx_mdef_11pomegranate_6kmeans_1initialize_centroids = {"initialize_centroids", (PyCFunction)__pyx_pw_11pomegranate_6kmeans_1initialize_centroids, METH_VARARGS|METH_KEYWORDS, __pyx_doc_11pomegranate_6kmeans_initialize_centroids};
    static PyObject *__pyx_pw_11pomegranate_6kmeans_1initialize_centroids(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyArrayObject *__pyx_v_X = 0;
      PyArrayObject *__pyx_v_weights = 0;
      int __pyx_v_k;
      PyObject *__pyx_v_init = 0;
      double __pyx_v_oversampling_factor;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("initialize_centroids (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_weights,&__pyx_n_s_k,&__pyx_n_s_init,&__pyx_n_s_oversampling_factor,0};
        PyObject* values[5] = {0,0,0,0,0};
        values[3] = ((PyObject *)__pyx_kp_s_first_k);
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_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;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            case  1:
            if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_weights)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("initialize_centroids", 0, 3, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
            }
            case  2:
            if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("initialize_centroids", 0, 3, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
            }
            case  3:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_init);
              if (value) { values[3] = value; kw_args--; }
            }
            case  4:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_oversampling_factor);
              if (value) { values[4] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize_centroids") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          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);
            values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_X = ((PyArrayObject *)values[0]);
        __pyx_v_weights = ((PyArrayObject *)values[1]);
        __pyx_v_k = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        __pyx_v_init = values[3];
        if (values[4]) {
          __pyx_v_oversampling_factor = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_oversampling_factor == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        } else {
          __pyx_v_oversampling_factor = ((double)0.95);
        }
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("initialize_centroids", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.initialize_centroids", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_weights), __pyx_ptype_5numpy_ndarray, 1, "weights", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_initialize_centroids(__pyx_self, __pyx_v_X, __pyx_v_weights, __pyx_v_k, __pyx_v_init, __pyx_v_oversampling_factor);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

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

    static PyObject *__pyx_pf_11pomegranate_6kmeans_initialize_centroids(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_weights, int __pyx_v_k, PyObject *__pyx_v_init, double __pyx_v_oversampling_factor) {
      int __pyx_v_n;
      int __pyx_v_d;
      int __pyx_v_count;
      int __pyx_v_i;
      int __pyx_v_j;
      int __pyx_v_l;
      int __pyx_v_m;
      double __pyx_v_distance;
      PyArrayObject *__pyx_v_centroids = 0;
      PyArrayObject *__pyx_v_min_distance = 0;
      PyArrayObject *__pyx_v_min_idxs = 0;
      double *__pyx_v_X_ptr;
      double *__pyx_v_weights_ptr;
      double *__pyx_v_min_distance_ptr;
      double *__pyx_v_centroids_ptr;
      int *__pyx_v_min_idxs_ptr;
      double __pyx_v_phi;
      PyObject *__pyx_v_idxs = NULL;
      PyObject *__pyx_v_idx = NULL;
      CYTHON_UNUSED PyObject *__pyx_v_iteration = NULL;
      PyObject *__pyx_v_prob = NULL;
      PyObject *__pyx_v_thresh = NULL;
      PyObject *__pyx_v_w = NULL;
      struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_clf = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("initialize_centroids", 0);
      __Pyx_INCREF((PyObject *)__pyx_v_weights);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_13);
      __Pyx_XDECREF(__pyx_t_14);
      __Pyx_AddTraceback("pomegranate.kmeans.initialize_centroids", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF((PyObject *)__pyx_v_centroids);
      __Pyx_XDECREF((PyObject *)__pyx_v_min_distance);
      __Pyx_XDECREF((PyObject *)__pyx_v_min_idxs);
      __Pyx_XDECREF(__pyx_v_idxs);
      __Pyx_XDECREF(__pyx_v_idx);
      __Pyx_XDECREF(__pyx_v_iteration);
      __Pyx_XDECREF(__pyx_v_prob);
      __Pyx_XDECREF(__pyx_v_thresh);
      __Pyx_XDECREF(__pyx_v_w);
      __Pyx_XDECREF((PyObject *)__pyx_v_clf);
      __Pyx_XDECREF((PyObject *)__pyx_v_weights);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__12 = PyTuple_Pack(29, __pyx_n_s_X, __pyx_n_s_weights, __pyx_n_s_k, __pyx_n_s_init, __pyx_n_s_oversampling_factor, __pyx_n_s_n, __pyx_n_s_d, __pyx_n_s_count, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_l, __pyx_n_s_m, __pyx_n_s_distance, __pyx_n_s_centroids, __pyx_n_s_min_distance, __pyx_n_s_min_idxs, __pyx_n_s_X_ptr, __pyx_n_s_weights_ptr, __pyx_n_s_min_distance_ptr, __pyx_n_s_centroids_ptr, __pyx_n_s_min_idxs_ptr, __pyx_n_s_phi, __pyx_n_s_idxs, __pyx_n_s_idx, __pyx_n_s_iteration, __pyx_n_s_prob, __pyx_n_s_thresh, __pyx_n_s_w, __pyx_n_s_clf); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_tuple__12);
      __Pyx_GIVEREF(__pyx_tuple__12);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_11pomegranate_6kmeans_1initialize_centroids, NULL, __pyx_n_s_pomegranate_kmeans); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_initialize_centroids, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     024: 	init='first-k', double oversampling_factor=0.95):

     025: 	"""Initialize the centroids for kmeans given a dataset.

     026:

     027: 	This function will take in a dataset and return the centroids found using

     028: 	some method. This is the initialization step of kmeans.

     029:

     030: 	Parameters

     031: 	----------

     032: 	X : numpy.ndarray, shape=(n_samples, n_dim)

     033: 		The dataset to identify centroids in.

     034:

     035: 	weights : numpy.ndarray, shape=(n_samples,)

     036: 		The weights associated with each of the samples.

     037:

     038: 	k : int

     039: 		The number of centroids to extract.

     040:

     041: 	init : str, one of 'first-k', 'random', 'kmeans++'

     042: 		'first-k' : use the first k samples as the centroids

     043: 		'random' : randomly select k samples as the centroids

     044: 		'kmeans++' : use the kmeans++ initialization algorithm, which

     045: 			iteratively selects the next centroid randomly, but weighted

     046: 			based on distance to nearest centroid, to be likely to choose

     047: 			good initializations

     048:

     049: 	Returns

     050: 	-------

     051:

     052: 	"""

     053:

    +054: 	cdef int n = X.shape[0], d = X.shape[1]

      __pyx_v_n = (__pyx_v_X->dimensions[0]);
      __pyx_v_d = (__pyx_v_X->dimensions[1]);

     055: 	cdef int count, i, j, l, m

     056: 	cdef double distance

     057: 	cdef numpy.ndarray centroids

     058: 	cdef numpy.ndarray min_distance

     059: 	cdef numpy.ndarray min_idxs

     060:

    +061: 	cdef double* X_ptr = <double*> X.data

      __pyx_v_X_ptr = ((double *)__pyx_v_X->data);

    +062: 	cdef double* weights_ptr = <double*> weights.data

      __pyx_v_weights_ptr = ((double *)__pyx_v_weights->data);

     063: 	cdef double* min_distance_ptr

     064: 	cdef double* centroids_ptr

     065: 	cdef int* min_idxs_ptr

     066: 	cdef double phi

     067:

    +068: 	weights = weights / weights.sum()

      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weights), __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_weights), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF_SET(__pyx_v_weights, ((PyArrayObject *)__pyx_t_2));
      __pyx_t_2 = 0;

     069:

    +070: 	if init not in ('first-k', 'random', 'kmeans++', 'kmeans||'):

      __Pyx_INCREF(__pyx_v_init);
      __pyx_t_2 = __pyx_v_init;
      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s_first_k, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
      } else {
        __pyx_t_4 = __pyx_t_5;
        goto __pyx_L4_bool_binop_done;
      }
      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_random, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
      } else {
        __pyx_t_4 = __pyx_t_5;
        goto __pyx_L4_bool_binop_done;
      }
      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s_kmeans, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
      } else {
        __pyx_t_4 = __pyx_t_5;
        goto __pyx_L4_bool_binop_done;
      }
      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s_kmeans_2, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __pyx_t_5;
      __pyx_L4_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_5 = (__pyx_t_4 != 0);
      if (__pyx_t_5) {
    /* … */
      }

    +071: 		raise ValueError("initialization must be one of 'first-k', 'random', or 'kmeans++'")

        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    /* … */
      __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_initialization_must_be_one_of_fi); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_tuple_);
      __Pyx_GIVEREF(__pyx_tuple_);

     072:

    +073: 	if init == 'first-k':

      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_init, __pyx_kp_s_first_k, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
    /* … */
        goto __pyx_L8;
      }

    +074: 		centroids = X[:k].copy()

        __pyx_t_1 = __Pyx_PyObject_GetSlice(((PyObject *)__pyx_v_X), 0, __pyx_v_k, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (__pyx_t_1) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else {
          __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_centroids = ((PyArrayObject *)__pyx_t_2);
        __pyx_t_2 = 0;

    +075: 	elif init == 'random':

      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_init, __pyx_n_s_random, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
    /* … */
        goto __pyx_L8;
      }

    +076: 		idxs = numpy.random.choice(n, size=k, replace=False, p=weights)

        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_random); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_choice); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_size, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_replace, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_p, ((PyObject *)__pyx_v_weights)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_idxs = __pyx_t_6;
        __pyx_t_6 = 0;

    +077: 		centroids = X[idxs].copy()

        __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_v_idxs); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (__pyx_t_3) {
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_centroids = ((PyArrayObject *)__pyx_t_6);
        __pyx_t_6 = 0;

     078:

    +079: 	elif init == 'kmeans++':

      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_init, __pyx_kp_s_kmeans, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
    /* … */
        goto __pyx_L8;
      }

    +080: 		centroids = numpy.zeros((k, d), dtype='float64')

        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_d); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
        __pyx_t_6 = 0;
        __pyx_t_3 = 0;
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __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_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_centroids = ((PyArrayObject *)__pyx_t_6);
        __pyx_t_6 = 0;

    +081: 		centroids_ptr = <double*> centroids.data

        __pyx_v_centroids_ptr = ((double *)__pyx_v_centroids->data);

     082:

    +083: 		idx = numpy.random.choice(n, p=weights)

        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_random); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_choice); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_p, ((PyObject *)__pyx_v_weights)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_idx = __pyx_t_1;
        __pyx_t_1 = 0;

    +084: 		centroids[0] = X[idx]

        __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_v_idx); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centroids), 0, __pyx_t_1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     085:

    +086: 		min_distance = numpy.zeros(n, dtype='float64') + INF

        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); 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_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyFloat_AddObjC(__pyx_t_6, __pyx_float_inf, Py_HUGE_VAL, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_min_distance = ((PyArrayObject *)__pyx_t_1);
        __pyx_t_1 = 0;

    +087: 		min_distance_ptr = <double*> min_distance.data

        __pyx_v_min_distance_ptr = ((double *)__pyx_v_min_distance->data);

     088:

    +089: 		for m in range(k-1):

        __pyx_t_7 = (__pyx_v_k - 1);
        for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
          __pyx_v_m = __pyx_t_8;

    +090: 			for i in range(n):

          __pyx_t_9 = __pyx_v_n;
          for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
            __pyx_v_i = __pyx_t_10;

    +091: 				distance = 0

            __pyx_v_distance = 0.0;

    +092: 				for j in range(d):

            __pyx_t_11 = __pyx_v_d;
            for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
              __pyx_v_j = __pyx_t_12;

    +093: 					distance += (X_ptr[i*d + j] - centroids_ptr[m*d + j]) ** 2

              __pyx_v_distance = (__pyx_v_distance + pow(((__pyx_v_X_ptr[((__pyx_v_i * __pyx_v_d) + __pyx_v_j)]) - (__pyx_v_centroids_ptr[((__pyx_v_m * __pyx_v_d) + __pyx_v_j)])), 2.0));
            }

    +094: 				distance *= weights_ptr[i]

            __pyx_v_distance = (__pyx_v_distance * (__pyx_v_weights_ptr[__pyx_v_i]));

     095:

    +096: 				if distance < min_distance_ptr[i]:

            __pyx_t_5 = ((__pyx_v_distance < (__pyx_v_min_distance_ptr[__pyx_v_i])) != 0);
            if (__pyx_t_5) {
    /* … */
            }
          }

    +097: 					min_distance_ptr[i] = distance

              (__pyx_v_min_distance_ptr[__pyx_v_i]) = __pyx_v_distance;

     098:

    +099: 			idx = numpy.random.choice(n, p=min_distance / min_distance.sum())

          __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_random); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_choice); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_min_distance), __pyx_n_s_sum); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_14 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_13))) {
            __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
            if (likely(__pyx_t_14)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_13, function);
            }
          }
          if (__pyx_t_14) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else {
            __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_min_distance), __pyx_t_2); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_p, __pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF_SET(__pyx_v_idx, __pyx_t_13);
          __pyx_t_13 = 0;

    +100: 			centroids[m+1] = X[idx]

          __pyx_t_13 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_v_idx); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_15 = (__pyx_v_m + 1);
          if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centroids), __pyx_t_15, __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }

     101:

    +102: 	elif init == 'kmeans||':

      __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_init, __pyx_kp_s_kmeans_2, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
    /* … */
      }
      __pyx_L8:;

    +103: 		phi = 0

        __pyx_v_phi = 0.0;

     104:

    +105: 		centroids = numpy.zeros((1, d))

        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_d); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_1);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_6 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_6) {
          __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_13);
        } else {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_centroids = ((PyArrayObject *)__pyx_t_13);
        __pyx_t_13 = 0;

    +106: 		idx = numpy.random.choice(n, p=weights)

        __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_random); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_choice); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_p, ((PyObject *)__pyx_v_weights)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_idx = __pyx_t_1;
        __pyx_t_1 = 0;

    +107: 		centroids[0] = X[idx]

        __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_v_idx); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centroids), 0, __pyx_t_1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     108:

    +109: 		min_distance = ((X - centroids[0]) ** 2).sum(axis=1)

        __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centroids), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PyNumber_Subtract(((PyObject *)__pyx_v_X), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyNumber_Power(__pyx_t_3, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sum); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_axis, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_min_distance = ((PyArrayObject *)__pyx_t_2);
        __pyx_t_2 = 0;

    +110: 		min_distance_ptr = <double*> min_distance.data

        __pyx_v_min_distance_ptr = ((double *)__pyx_v_min_distance->data);

     111:

    +112: 		min_idxs = numpy.zeros(n, dtype='int32')

        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_n_s_int32) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_min_idxs = ((PyArrayObject *)__pyx_t_13);
        __pyx_t_13 = 0;

    +113: 		min_idxs_ptr = <int*> min_idxs.data

        __pyx_v_min_idxs_ptr = ((int *)__pyx_v_min_idxs->data);

     114:

    +115: 		phi = min_distance.sum()

        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_min_distance), __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        if (__pyx_t_3) {
          __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_t_13); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_v_phi = __pyx_t_16;

    +116: 		count = 1

        __pyx_v_count = 1;

     117:

    +118: 		for iteration in range(int(clog10(phi))):

        __pyx_t_13 = PyFloat_FromDouble(log10(__pyx_v_phi)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_13);
        __pyx_t_13 = 0;
        __pyx_t_13 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_13);
        __pyx_t_13 = 0;
        __pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_2, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (likely(PyList_CheckExact(__pyx_t_13)) || PyTuple_CheckExact(__pyx_t_13)) {
          __pyx_t_2 = __pyx_t_13; __Pyx_INCREF(__pyx_t_2); __pyx_t_17 = 0;
          __pyx_t_18 = NULL;
        } else {
          __pyx_t_17 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_18 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        for (;;) {
          if (likely(!__pyx_t_18)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_13 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_13); __pyx_t_17++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #else
              __pyx_t_13 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              __Pyx_GOTREF(__pyx_t_13);
              #endif
            } else {
              if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_13 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_17); __Pyx_INCREF(__pyx_t_13); __pyx_t_17++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #else
              __pyx_t_13 = PySequence_ITEM(__pyx_t_2, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              __Pyx_GOTREF(__pyx_t_13);
              #endif
            }
          } else {
            __pyx_t_13 = __pyx_t_18(__pyx_t_2);
            if (unlikely(!__pyx_t_13)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_13);
          }
          __Pyx_XDECREF_SET(__pyx_v_iteration, __pyx_t_13);
          __pyx_t_13 = 0;
    /* … */
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +119: 			prob = numpy.random.uniform(0, 1, size=(n,))

          __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_random); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_uniform); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
          __pyx_t_1 = 0;
          if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_size, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__2, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF_SET(__pyx_v_prob, __pyx_t_6);
          __pyx_t_6 = 0;
    /* … */
      __pyx_tuple__2 = PyTuple_Pack(2, __pyx_int_0, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_tuple__2);
      __Pyx_GIVEREF(__pyx_tuple__2);

    +120: 			thresh = oversampling_factor * min_distance / phi

          __pyx_t_6 = PyFloat_FromDouble(__pyx_v_oversampling_factor); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, ((PyObject *)__pyx_v_min_distance)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyFloat_FromDouble(__pyx_v_phi); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_13 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF_SET(__pyx_v_thresh, __pyx_t_13);
          __pyx_t_13 = 0;

     121:

    +122: 			centroids = numpy.concatenate((centroids, X[prob < thresh]))

          __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_concatenate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyObject_RichCompare(__pyx_v_prob, __pyx_v_thresh, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_t_6); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(((PyObject *)__pyx_v_centroids));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_centroids));
          PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_centroids));
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_1 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
            }
          }
          if (!__pyx_t_1) {
            __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_GOTREF(__pyx_t_13);
          } else {
            __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_14);
            __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL;
            __Pyx_GIVEREF(__pyx_t_6);
            PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_6);
            __pyx_t_6 = 0;
            __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          }
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF_SET(__pyx_v_centroids, ((PyArrayObject *)__pyx_t_13));
          __pyx_t_13 = 0;

    +123: 			centroids_ptr = <double*> centroids.data

          __pyx_v_centroids_ptr = ((double *)__pyx_v_centroids->data);

    +124: 			m = centroids.shape[0] - count

          __pyx_v_m = ((__pyx_v_centroids->dimensions[0]) - __pyx_v_count);

     125:

    +126: 			if m > 0:

          __pyx_t_5 = ((__pyx_v_m > 0) != 0);
          if (__pyx_t_5) {
    /* … */
          }

    +127: 				for i in range(n):

            __pyx_t_8 = __pyx_v_n;
            for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
              __pyx_v_i = __pyx_t_9;

    +128: 					for l in range(m):

              __pyx_t_10 = __pyx_v_m;
              for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
                __pyx_v_l = __pyx_t_11;

    +129: 						distance = 0

                __pyx_v_distance = 0.0;

    +130: 						for j in range(d):

                __pyx_t_12 = __pyx_v_d;
                for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_12; __pyx_t_19+=1) {
                  __pyx_v_j = __pyx_t_19;

    +131: 							distance += (X_ptr[i*d + j] - centroids_ptr[(l + count)*d + j]) ** 2

                  __pyx_v_distance = (__pyx_v_distance + pow(((__pyx_v_X_ptr[((__pyx_v_i * __pyx_v_d) + __pyx_v_j)]) - (__pyx_v_centroids_ptr[(((__pyx_v_l + __pyx_v_count) * __pyx_v_d) + __pyx_v_j)])), 2.0));
                }

     132:

    +133: 						if distance < min_distance_ptr[i]:

                __pyx_t_5 = ((__pyx_v_distance < (__pyx_v_min_distance_ptr[__pyx_v_i])) != 0);
                if (__pyx_t_5) {
    /* … */
                }
              }
            }

    +134: 							phi += distance - min_distance_ptr[i]

                  __pyx_v_phi = (__pyx_v_phi + (__pyx_v_distance - (__pyx_v_min_distance_ptr[__pyx_v_i])));

    +135: 							min_distance_ptr[i] = distance

                  (__pyx_v_min_distance_ptr[__pyx_v_i]) = __pyx_v_distance;

    +136: 							min_idxs_ptr[i] = l + count

                  (__pyx_v_min_idxs_ptr[__pyx_v_i]) = (__pyx_v_l + __pyx_v_count);

     137:

    +138: 				count = centroids.shape[0]

            __pyx_v_count = (__pyx_v_centroids->dimensions[0]);

     139:

    +140: 		w = numpy.bincount(min_idxs)

        __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_bincount); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_13) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_min_idxs)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL;
          __Pyx_INCREF(((PyObject *)__pyx_v_min_idxs));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_min_idxs));
          PyTuple_SET_ITEM(__pyx_t_14, 0+1, ((PyObject *)__pyx_v_min_idxs));
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_w = __pyx_t_2;
        __pyx_t_2 = 0;

     141:

    +142: 		clf = Kmeans(k, 'kmeans++', 1)

        __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
        __Pyx_INCREF(__pyx_kp_s_kmeans);
        __Pyx_GIVEREF(__pyx_kp_s_kmeans);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_kmeans);
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_11pomegranate_6kmeans_Kmeans), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_clf = ((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_t_2);
        __pyx_t_2 = 0;

    +143: 		clf.fit(centroids, w)

        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_clf), __pyx_n_s_fit); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_14 = NULL;
        __pyx_t_17 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_17 = 1;
          }
        }
        __pyx_t_13 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_centroids));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_centroids));
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_17, ((PyObject *)__pyx_v_centroids));
        __Pyx_INCREF(__pyx_v_w);
        __Pyx_GIVEREF(__pyx_v_w);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_17, __pyx_v_w);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +144: 		centroids = clf.centroids

        __pyx_t_2 = ((PyObject *)__pyx_v_clf->centroids);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_DECREF_SET(__pyx_v_centroids, ((PyArrayObject *)__pyx_t_2));
        __pyx_t_2 = 0;

     145:

    +146: 	return centroids

      __Pyx_XDECREF(__pyx_r);
      if (unlikely(!__pyx_v_centroids)) { __Pyx_RaiseUnboundLocalError("centroids"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
      __Pyx_INCREF(((PyObject *)__pyx_v_centroids));
      __pyx_r = ((PyObject *)__pyx_v_centroids);
      goto __pyx_L0;

     147:

    +148: cdef class Kmeans(Model):

    struct __pyx_obj_11pomegranate_6kmeans_Kmeans {
      struct __pyx_obj_11pomegranate_4base_Model __pyx_base;
      int k;
      int n_init;
      PyObject *init;
      PyArrayObject *centroids;
      double *centroids_ptr;
      double *summary_sizes;
      double *summary_weights;
    };
    /* … */
    struct __pyx_vtabstruct_11pomegranate_6kmeans_Kmeans {
      struct __pyx_vtabstruct_11pomegranate_4base_Model __pyx_base;
      void (*_predict)(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *, double *, int *, int);
    };
    static struct __pyx_vtabstruct_11pomegranate_6kmeans_Kmeans *__pyx_vtabptr_11pomegranate_6kmeans_Kmeans;

     149: 	"""A kmeans model.

     150:

     151: 	Kmeans is not a probabilistic model, but it is used in the kmeans++

     152: 	initialization for GMMs. In essence, a point is selected as the center for

     153: 	one component and then remaining points are selected.

     154:

     155: 	Parameters

     156: 	----------

     157: 	k : int

     158: 		The number of centroids.

     159:

     160: 	centroids : numpy.ndarray or None, optional

     161: 		The centroids to be used for this kmeans clusterer, if known ahead of

     162: 		time. These centroids can either be refined on future data, or used

     163: 		for predictions in the future. If None, then it will begin clustering

     164: 		on the first batch of data that it sees.

     165: 		Default is None.

     166:

     167: 	Attributes

     168: 	----------

     169: 	k : int

     170: 		The number of centroids

     171:

     172: 	centroids : array-like, shape (k, n_dim)

     173: 		The means of the centroid points.

     174: 	"""

     175:

    +176: 	cdef public int k

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_1k_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_1k_1__get__(PyObject *__pyx_v_self) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_1k___get__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_1k___get__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__", 0);
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->k); 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_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.k.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_1k_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_1k_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_1k_2__set__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), ((PyObject *)__pyx_v_value));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_11pomegranate_6kmeans_6Kmeans_1k_2__set__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_value) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__set__", 0);
      __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->k = __pyx_t_1;

      /* function exit code */
      __pyx_r = 0;
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.k.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     177: 	cdef int n_init

     178: 	cdef str init

    +179: 	cdef public numpy.ndarray centroids

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_1__get__(PyObject *__pyx_v_self) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids___get__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids___get__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__", 0);
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(((PyObject *)__pyx_v_self->centroids));
      __pyx_r = ((PyObject *)__pyx_v_self->centroids);
      goto __pyx_L0;

      /* function exit code */
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids_2__set__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), ((PyObject *)__pyx_v_value));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids_2__set__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_value) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__set__", 0);
      if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __pyx_v_value;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_self->centroids);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
      __pyx_v_self->centroids = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* function exit code */
      __pyx_r = 0;
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.centroids.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_5__del__(PyObject *__pyx_v_self); /*proto*/
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_9centroids_5__del__(PyObject *__pyx_v_self) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids_4__del__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_11pomegranate_6kmeans_6Kmeans_9centroids_4__del__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__del__", 0);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_GOTREF(__pyx_v_self->centroids);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
      __pyx_v_self->centroids = ((PyArrayObject *)Py_None);

      /* function exit code */
      __pyx_r = 0;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     180: 	cdef double* centroids_ptr

     181: 	cdef double* summary_sizes

     182: 	cdef double* summary_weights

     183:

    +184: 	def __init__(self, k, init='kmeans++', n_init=10):

    /* Python wrapper */
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static int __pyx_pw_11pomegranate_6kmeans_6Kmeans_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_k = 0;
      PyObject *__pyx_v_init = 0;
      PyObject *__pyx_v_n_init = 0;
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_k,&__pyx_n_s_init,&__pyx_n_s_n_init,0};
        PyObject* values[3] = {0,0,0};
        values[1] = ((PyObject *)__pyx_kp_s_kmeans);
        values[2] = ((PyObject *)__pyx_int_10);
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            case  1:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_init);
              if (value) { values[1] = value; kw_args--; }
            }
            case  2:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n_init);
              if (value) { values[2] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          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);
            break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_k = values[0];
        __pyx_v_init = values[1];
        __pyx_v_n_init = values[2];
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return -1;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans___init__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), __pyx_v_k, __pyx_v_init, __pyx_v_n_init);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_11pomegranate_6kmeans_6Kmeans___init__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_k, PyObject *__pyx_v_init, PyObject *__pyx_v_n_init) {
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__", 0);
    /* … */
      /* function exit code */
      __pyx_r = 0;
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +185: 		self.k = k

      __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_k); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->k = __pyx_t_1;

    +186: 		self.d = 0

      __pyx_v_self->__pyx_base.d = 0;

    +187: 		self.n_init = n_init

      __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n_init); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->n_init = __pyx_t_1;

     188:

    +189: 		if isinstance(init, (list, numpy.ndarray)):

      __pyx_t_3 = PyList_Check(__pyx_v_init);
      __pyx_t_4 = (__pyx_t_3 != 0);
      if (!__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L4_bool_binop_done;
      }
      __pyx_t_4 = __Pyx_TypeCheck(__pyx_v_init, __pyx_ptype_5numpy_ndarray);
      __pyx_t_3 = (__pyx_t_4 != 0);
      __pyx_t_2 = __pyx_t_3;
      __pyx_L4_bool_binop_done:;
      __pyx_t_3 = (__pyx_t_2 != 0);
      if (__pyx_t_3) {
    /* … */
        goto __pyx_L3;
      }

    +190: 			self.centroids = numpy.array(init, dtype='float64', ndmin=2)

        __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_init);
        __Pyx_GIVEREF(__pyx_v_init);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_init);
        __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_ndmin, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GIVEREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_v_self->centroids);
        __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
        __pyx_v_self->centroids = ((PyArrayObject *)__pyx_t_8);
        __pyx_t_8 = 0;

    +191: 			self.centroids_ptr = <double*> self.centroids.data

        __pyx_v_self->centroids_ptr = ((double *)__pyx_v_self->centroids->data);

    +192: 		elif isinstance(init, str):

      __pyx_t_3 = PyString_Check(__pyx_v_init);
      __pyx_t_2 = (__pyx_t_3 != 0);
      if (__pyx_t_2) {
    /* … */
      }
      __pyx_L3:;

    +193: 			self.init = init

        if (!(likely(PyString_CheckExact(__pyx_v_init))||((__pyx_v_init) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_init)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_8 = __pyx_v_init;
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_v_self->init);
        __Pyx_DECREF(__pyx_v_self->init);
        __pyx_v_self->init = ((PyObject*)__pyx_t_8);
        __pyx_t_8 = 0;

     194:

    +195: 	def __dealloc__(self):

    /* Python wrapper */
    static void __pyx_pw_11pomegranate_6kmeans_6Kmeans_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
    static void __pyx_pw_11pomegranate_6kmeans_6Kmeans_3__dealloc__(PyObject *__pyx_v_self) {
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
      __pyx_pf_11pomegranate_6kmeans_6Kmeans_2__dealloc__(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
    }

    static void __pyx_pf_11pomegranate_6kmeans_6Kmeans_2__dealloc__(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self) {
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__dealloc__", 0);
    /* … */
      /* function exit code */
      __Pyx_RefNannyFinishContext();
    }

    +196: 		free(self.summary_sizes)

      free(__pyx_v_self->summary_sizes);

    +197: 		free(self.summary_weights)

      free(__pyx_v_self->summary_weights);

     198:

    +199: 	def predict(self, X):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_5predict(PyObject *__pyx_v_self, PyObject *__pyx_v_X); /*proto*/
    static char __pyx_doc_11pomegranate_6kmeans_6Kmeans_4predict[] = "Predict nearest centroid for each point.\n\n\t\tParameters\n\t\t----------\n\t\tX : array-like, shape (n_samples, n_dim)\n\t\t\tThe data to fit to.\n\n\t\tReturns\n\t\t-------\n\t\ty : array-like, shape (n_samples,)\n\t\t\tThe index of the nearest centroid.\n\t\t";
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_5predict(PyObject *__pyx_v_self, PyObject *__pyx_v_X) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("predict (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_4predict(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), ((PyObject *)__pyx_v_X));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_4predict(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_X) {
      double *__pyx_v_X_ptr;
      int __pyx_v_n;
      PyArrayObject *__pyx_v_y = 0;
      int *__pyx_v_y_ptr;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("predict", 0);
      __Pyx_INCREF(__pyx_v_X);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.predict", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF((PyObject *)__pyx_v_y);
      __Pyx_XDECREF(__pyx_v_X);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     200: 		"""Predict nearest centroid for each point.

     201:

     202: 		Parameters

     203: 		----------

     204: 		X : array-like, shape (n_samples, n_dim)

     205: 			The data to fit to.

     206:

     207: 		Returns

     208: 		-------

     209: 		y : array-like, shape (n_samples,)

     210: 			The index of the nearest centroid.

     211: 		"""

     212:

    +213: 		X = numpy.array(X, dtype='float64')

      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_X);
      __Pyx_GIVEREF(__pyx_v_X);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_X);
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_4);
      __pyx_t_4 = 0;

    +214: 		cdef double* X_ptr = <double*> (<numpy.ndarray> X).data

      __pyx_v_X_ptr = ((double *)((PyArrayObject *)__pyx_v_X)->data);

    +215: 		cdef int n = len(X)

      __pyx_t_5 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_n = __pyx_t_5;

     216:

    +217: 		cdef numpy.ndarray y = numpy.zeros(n, dtype='int32')

      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_n_s_int32) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_y = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;

    +218: 		cdef int* y_ptr = <int*> y.data

      __pyx_v_y_ptr = ((int *)__pyx_v_y->data);

     219:

    +220: 		self.d = X.shape[1]

      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_self->__pyx_base.d = __pyx_t_6;

     221:

    +222: 		with nogil:

      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {
    /* … */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L5;
            }
            __pyx_L5:;
          }
      }

    +223: 			self._predict(X_ptr, y_ptr, n)

            ((struct __pyx_vtabstruct_11pomegranate_6kmeans_Kmeans *)__pyx_v_self->__pyx_base.__pyx_vtab)->_predict(__pyx_v_self, __pyx_v_X_ptr, __pyx_v_y_ptr, __pyx_v_n);
          }

     224:

    +225: 		return y

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __pyx_r = ((PyObject *)__pyx_v_y);
      goto __pyx_L0;

     226:

    +227: 	cdef void _predict(self, double* X, int* y, int n) nogil:

    static void __pyx_f_11pomegranate_6kmeans_6Kmeans__predict(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, double *__pyx_v_X, int *__pyx_v_y, int __pyx_v_n) {
      int __pyx_v_i;
      int __pyx_v_j;
      int __pyx_v_l;
      int __pyx_v_k;
      int __pyx_v_d;
      double __pyx_v_dist;
      double __pyx_v_min_dist;
    /* … */
      /* function exit code */
    }

    +228: 		cdef int i, j, l, k = self.k, d = self.d

      __pyx_t_1 = __pyx_v_self->k;
      __pyx_v_k = __pyx_t_1;
      __pyx_t_1 = __pyx_v_self->__pyx_base.d;
      __pyx_v_d = __pyx_t_1;

     229: 		cdef double dist, min_dist

     230:

    +231: 		for i in range(n):

      __pyx_t_1 = __pyx_v_n;
      for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
        __pyx_v_i = __pyx_t_2;

    +232: 			min_dist = INF

        __pyx_v_min_dist = Py_HUGE_VAL;

     233:

    +234: 			for j in range(k):

        __pyx_t_3 = __pyx_v_k;
        for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
          __pyx_v_j = __pyx_t_4;

    +235: 				dist = 0.0

          __pyx_v_dist = 0.0;

     236:

    +237: 				for l in range(d):

          __pyx_t_5 = __pyx_v_d;
          for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
            __pyx_v_l = __pyx_t_6;

    +238: 					dist += (X[i*d + l] - self.centroids_ptr[j*d + l]) ** 2.0

            __pyx_v_dist = (__pyx_v_dist + pow(((__pyx_v_X[((__pyx_v_i * __pyx_v_d) + __pyx_v_l)]) - (__pyx_v_self->centroids_ptr[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)])), 2.0));
          }

     239:

    +240: 				if dist < min_dist:

          __pyx_t_7 = ((__pyx_v_dist < __pyx_v_min_dist) != 0);
          if (__pyx_t_7) {
    /* … */
          }
        }
      }

    +241: 					min_dist = dist

            __pyx_v_min_dist = __pyx_v_dist;

    +242: 					y[i] = j

            (__pyx_v_y[__pyx_v_i]) = __pyx_v_j;

     243:

    +244: 	def fit(self, X, weights=None, inertia=0.0, stop_threshold=1e-3,

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_7fit(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static char __pyx_doc_11pomegranate_6kmeans_6Kmeans_6fit[] = "Fit the model to the data using k centroids.\n\n\t\tParameters\n\t\t----------\n\t\tX : array-like, shape (n_samples, n_dim)\n\t\t\tThe data to fit to.\n\n\t\tweights : array-like, shape (n_samples,), optional\n\t\t\tThe initial weights of each sample in the matrix. If nothing is\n\t\t\tpassed in then each sample is assumed to be the same weight.\n\t\t\tDefault is None.\n\n\t\tinertia : double, optional\n\t\t\tThe weight of the previous parameters of the model. The new\n\t\t\tparameters will roughly be\n\t\t\told_param*inertia + new_param*(1-inertia), so an inertia of 0 means\n\t\t\tignore the old parameters, whereas an inertia of 1 means ignore\n\t\t\tthe new parameters.\n\t\t\tDefault is 0.0.\n\n\t\tstop_threshold : double, optional, positive\n\t\t\tThe threshold at which EM will terminate for the improvement of\n\t\t\tthe model. If the model does not improve its fit of the data by a\n\t\t\tlog probability of 0.1 then terminate.\n\t\t\tDefault is 0.1.\n\n\t\tmax_iterations : int, optional\n\t\t\tThe maximum number of iterations to run for. Default is 1e3.\n\n\t\tverbose : bool, optional\n\t\t\tWhether or not to print out improvement information over\n\t\t\titerations.\n\t\t\tDefault is False.\n\n\t\tReturns\n\t\t-------\n\t\tNone\n\t\t";
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_7fit(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_X = 0;
      PyObject *__pyx_v_weights = 0;
      PyObject *__pyx_v_inertia = 0;
      PyObject *__pyx_v_stop_threshold = 0;
      PyObject *__pyx_v_max_iterations = 0;
      PyObject *__pyx_v_verbose = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("fit (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_weights,&__pyx_n_s_inertia,&__pyx_n_s_stop_threshold,&__pyx_n_s_max_iterations,&__pyx_n_s_verbose,0};
        PyObject* values[6] = {0,0,0,0,0,0};
        values[1] = ((PyObject *)Py_None);
        values[2] = ((PyObject *)__pyx_float_0_0);
        values[3] = ((PyObject *)__pyx_float_1eneg_3);
        values[4] = ((PyObject *)__pyx_float_1e3);
    /* … */
      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_6fit(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_weights, PyObject *__pyx_v_inertia, PyObject *__pyx_v_stop_threshold, PyObject *__pyx_v_max_iterations, PyObject *__pyx_v_verbose) {
      PyObject *__pyx_v_best_centroids = NULL;
      PyObject *__pyx_v_best_distance = NULL;
      CYTHON_UNUSED int __pyx_v_i;
      PyObject *__pyx_v_initial_distance_sum = NULL;
      PyObject *__pyx_v_iteration = NULL;
      PyObject *__pyx_v_improvement = NULL;
      PyObject *__pyx_v_distance_sum = NULL;
      PyObject *__pyx_v_last_distance_sum = NULL;
      PyObject *__pyx_v_total_improvement = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("fit", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.fit", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_best_centroids);
      __Pyx_XDECREF(__pyx_v_best_distance);
      __Pyx_XDECREF(__pyx_v_initial_distance_sum);
      __Pyx_XDECREF(__pyx_v_iteration);
      __Pyx_XDECREF(__pyx_v_improvement);
      __Pyx_XDECREF(__pyx_v_distance_sum);
      __Pyx_XDECREF(__pyx_v_last_distance_sum);
      __Pyx_XDECREF(__pyx_v_total_improvement);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +245: 		    max_iterations=1e3, verbose=False):

        values[5] = ((PyObject *)Py_False);
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            case  1:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_weights);
              if (value) { values[1] = value; kw_args--; }
            }
            case  2:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_inertia);
              if (value) { values[2] = value; kw_args--; }
            }
            case  3:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stop_threshold);
              if (value) { values[3] = value; kw_args--; }
            }
            case  4:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iterations);
              if (value) { values[4] = value; kw_args--; }
            }
            case  5:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_verbose);
              if (value) { values[5] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          switch (PyTuple_GET_SIZE(__pyx_args)) {
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_X = values[0];
        __pyx_v_weights = values[1];
        __pyx_v_inertia = values[2];
        __pyx_v_stop_threshold = values[3];
        __pyx_v_max_iterations = values[4];
        __pyx_v_verbose = values[5];
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("fit", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.fit", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_6fit(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), __pyx_v_X, __pyx_v_weights, __pyx_v_inertia, __pyx_v_stop_threshold, __pyx_v_max_iterations, __pyx_v_verbose);

     246: 		"""Fit the model to the data using k centroids.

     247:

     248: 		Parameters

     249: 		----------

     250: 		X : array-like, shape (n_samples, n_dim)

     251: 			The data to fit to.

     252:

     253: 		weights : array-like, shape (n_samples,), optional

     254: 			The initial weights of each sample in the matrix. If nothing is

     255: 			passed in then each sample is assumed to be the same weight.

     256: 			Default is None.

     257:

     258: 		inertia : double, optional

     259: 			The weight of the previous parameters of the model. The new

     260: 			parameters will roughly be

     261: 			old_param*inertia + new_param*(1-inertia), so an inertia of 0 means

     262: 			ignore the old parameters, whereas an inertia of 1 means ignore

     263: 			the new parameters.

     264: 			Default is 0.0.

     265:

     266: 		stop_threshold : double, optional, positive

     267: 			The threshold at which EM will terminate for the improvement of

     268: 			the model. If the model does not improve its fit of the data by a

     269: 			log probability of 0.1 then terminate.

     270: 			Default is 0.1.

     271:

     272: 		max_iterations : int, optional

     273: 			The maximum number of iterations to run for. Default is 1e3.

     274:

     275: 		verbose : bool, optional

     276: 			Whether or not to print out improvement information over

     277: 			iterations.

     278: 			Default is False.

     279:

     280: 		Returns

     281: 		-------

     282: 		None

     283: 		"""

     284:

    +285: 		best_centroids, best_distance = None, INF

      __pyx_t_1 = Py_None;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = __pyx_float_inf;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_v_best_centroids = __pyx_t_1;
      __pyx_t_1 = 0;
      __pyx_v_best_distance = __pyx_t_2;
      __pyx_t_2 = 0;

     286:

    +287: 		for i in range(self.n_init):

      __pyx_t_3 = __pyx_v_self->n_init;
      for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
        __pyx_v_i = __pyx_t_4;

    +288: 			self.d = 0

        __pyx_v_self->__pyx_base.d = 0;

    +289: 			initial_distance_sum = INF

        __Pyx_INCREF(__pyx_float_inf);
        __Pyx_XDECREF_SET(__pyx_v_initial_distance_sum, __pyx_float_inf);

    +290: 			iteration, improvement = 0, INF

        __pyx_t_2 = __pyx_int_0;
        __Pyx_INCREF(__pyx_t_2);
        __pyx_t_1 = __pyx_float_inf;
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_XDECREF_SET(__pyx_v_iteration, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_improvement, __pyx_t_1);
        __pyx_t_1 = 0;

     291:

    +292: 			while improvement > stop_threshold and iteration < max_iterations + 1:

        while (1) {
          __pyx_t_1 = PyObject_RichCompare(__pyx_v_improvement, __pyx_v_stop_threshold, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_6) {
          } else {
            __pyx_t_5 = __pyx_t_6;
            goto __pyx_L7_bool_binop_done;
          }
          __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_max_iterations, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = PyObject_RichCompare(__pyx_v_iteration, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_5 = __pyx_t_6;
          __pyx_L7_bool_binop_done:;
          if (!__pyx_t_5) break;

    +293: 				self.from_summaries(inertia)

          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_from_summaries); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (!__pyx_t_7) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_inertia); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
          } else {
            __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
            __Pyx_INCREF(__pyx_v_inertia);
            __Pyx_GIVEREF(__pyx_v_inertia);
            PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_inertia);
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +294: 				distance_sum = self.summarize(X, weights)

          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_summarize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = NULL;
          __pyx_t_9 = 0;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
              __pyx_t_9 = 1;
            }
          }
          __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          if (__pyx_t_8) {
            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
          }
          __Pyx_INCREF(__pyx_v_X);
          __Pyx_GIVEREF(__pyx_v_X);
          PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_v_X);
          __Pyx_INCREF(__pyx_v_weights);
          __Pyx_GIVEREF(__pyx_v_weights);
          PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_v_weights);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_distance_sum, __pyx_t_2);
          __pyx_t_2 = 0;

     295:

    +296: 				if iteration == 0:

          __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_v_iteration, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (__pyx_t_5) {
    /* … */
            goto __pyx_L9;
          }

    +297: 					initial_distance_sum = distance_sum

            __Pyx_INCREF(__pyx_v_distance_sum);
            __Pyx_DECREF_SET(__pyx_v_initial_distance_sum, __pyx_v_distance_sum);

     298: 				else:

    +299: 					improvement = distance_sum - last_distance_sum

          /*else*/ {
            if (unlikely(!__pyx_v_last_distance_sum)) { __Pyx_RaiseUnboundLocalError("last_distance_sum"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
            __pyx_t_2 = PyNumber_Subtract(__pyx_v_distance_sum, __pyx_v_last_distance_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF_SET(__pyx_v_improvement, __pyx_t_2);
            __pyx_t_2 = 0;

     300:

    +301: 					if verbose:

            __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_verbose); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            if (__pyx_t_5) {
    /* … */
            }
          }
          __pyx_L9:;

    +302: 						print("Improvement: {}".format(improvement))

              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Improvement, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_7 = NULL;
              if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
                __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
                if (likely(__pyx_t_7)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                  __Pyx_INCREF(__pyx_t_7);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_1, function);
                }
              }
              if (!__pyx_t_7) {
                __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_improvement); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_2);
              } else {
                __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_8);
                __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
                __Pyx_INCREF(__pyx_v_improvement);
                __Pyx_GIVEREF(__pyx_v_improvement);
                PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_improvement);
                __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
              }
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              if (__Pyx_PrintOne(0, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     303:

    +304: 				iteration += 1

          __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_iteration, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF_SET(__pyx_v_iteration, __pyx_t_2);
          __pyx_t_2 = 0;

    +305: 				last_distance_sum = distance_sum

          __Pyx_INCREF(__pyx_v_distance_sum);
          __Pyx_XDECREF_SET(__pyx_v_last_distance_sum, __pyx_v_distance_sum);
        }

     306:

    +307: 			self.clear_summaries()

        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clear_summaries); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (__pyx_t_8) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else {
          __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +308: 			total_improvement = last_distance_sum - initial_distance_sum

        if (unlikely(!__pyx_v_last_distance_sum)) { __Pyx_RaiseUnboundLocalError("last_distance_sum"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_last_distance_sum, __pyx_v_initial_distance_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_total_improvement, __pyx_t_2);
        __pyx_t_2 = 0;

     309:

    +310: 			if verbose:

        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_verbose); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_5) {
    /* … */
        }

    +311: 				print("Total Improvement: {}".format(total_improvement))

          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Total_Improvement, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (!__pyx_t_8) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_total_improvement); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
          } else {
            __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
            __Pyx_INCREF(__pyx_v_total_improvement);
            __Pyx_GIVEREF(__pyx_v_total_improvement);
            PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_total_improvement);
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__Pyx_PrintOne(0, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     312:

    +313: 			if last_distance_sum < best_distance:

        if (unlikely(!__pyx_v_last_distance_sum)) { __Pyx_RaiseUnboundLocalError("last_distance_sum"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
        __pyx_t_2 = PyObject_RichCompare(__pyx_v_last_distance_sum, __pyx_v_best_distance, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__pyx_t_5) {
    /* … */
        }
      }

    +314: 				best_centroids = self.centroids.copy()

          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->centroids), __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (__pyx_t_7) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          } else {
            __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF_SET(__pyx_v_best_centroids, __pyx_t_2);
          __pyx_t_2 = 0;

    +315: 				best_distance = last_distance_sum

          if (unlikely(!__pyx_v_last_distance_sum)) { __Pyx_RaiseUnboundLocalError("last_distance_sum"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
          __Pyx_INCREF(__pyx_v_last_distance_sum);
          __Pyx_DECREF_SET(__pyx_v_best_distance, __pyx_v_last_distance_sum);

     316:

    +317: 		self.centroids = best_centroids

      if (!(likely(((__pyx_v_best_centroids) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_best_centroids, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __pyx_v_best_centroids;
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_v_self->centroids);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
      __pyx_v_self->centroids = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;

    +318: 		self.centroids_ptr = <double*> self.centroids.data

      __pyx_v_self->centroids_ptr = ((double *)__pyx_v_self->centroids->data);

    +319: 		return best_distance

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_best_distance);
      __pyx_r = __pyx_v_best_distance;
      goto __pyx_L0;

     320:

    +321: 	def summarize(self, X, weights=None):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_9summarize(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static char __pyx_doc_11pomegranate_6kmeans_6Kmeans_8summarize[] = "Summarize the points into sufficient statistics for a future update.\n\n\t\tParameters\n\t\t----------\n\t\tX : array-like, shape (n_samples, n_dim)\n\t\t\tThe data to fit to.\n\n\t\tweights : array-like, shape (n_samples,), optional\n\t\t\tThe initial weights of each sample in the matrix. If nothing is\n\t\t\tpassed in then each sample is assumed to be the same weight.\n\t\t\tDefault is None.\n\n\t\tReturns\n\t\t-------\n\t\tdist : double\n\t\t\tThe negative total euclidean distance between each point and its\n\t\t\tnearest centroid. This is not a probabilitity, and the negative is\n\t\t\treturned to fit in with the idea of large negative numbers being\n\t\t\tworse than smaller negative numbers, such as with log\n\t\t\tprobabilities.\n\t\t";
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_9summarize(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_X = 0;
      PyObject *__pyx_v_weights = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("summarize (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_weights,0};
        PyObject* values[2] = {0,0};
        values[1] = ((PyObject *)Py_None);
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            case  1:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_weights);
              if (value) { values[1] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "summarize") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          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);
            break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_X = values[0];
        __pyx_v_weights = values[1];
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("summarize", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.summarize", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_8summarize(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), __pyx_v_X, __pyx_v_weights);

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_8summarize(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_weights) {
      PyArrayObject *__pyx_v_X_ndarray = 0;
      PyArrayObject *__pyx_v_weights_ndarray = 0;
      int __pyx_v_n;
      int __pyx_v_d;
      double *__pyx_v_X_ptr;
      double __pyx_v_dist;
      double *__pyx_v_weights_ptr;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("summarize", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.summarize", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF((PyObject *)__pyx_v_X_ndarray);
      __Pyx_XDECREF((PyObject *)__pyx_v_weights_ndarray);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     322: 		"""Summarize the points into sufficient statistics for a future update.

     323:

     324: 		Parameters

     325: 		----------

     326: 		X : array-like, shape (n_samples, n_dim)

     327: 			The data to fit to.

     328:

     329: 		weights : array-like, shape (n_samples,), optional

     330: 			The initial weights of each sample in the matrix. If nothing is

     331: 			passed in then each sample is assumed to be the same weight.

     332: 			Default is None.

     333:

     334: 		Returns

     335: 		-------

     336: 		dist : double

     337: 			The negative total euclidean distance between each point and its

     338: 			nearest centroid. This is not a probabilitity, and the negative is

     339: 			returned to fit in with the idea of large negative numbers being

     340: 			worse than smaller negative numbers, such as with log

     341: 			probabilities.

     342: 		"""

     343:

    +344: 		cdef numpy.ndarray X_ndarray = numpy.array(X, dtype='float64')

      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_X);
      __Pyx_GIVEREF(__pyx_v_X);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_X);
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_X_ndarray = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;

     345: 		cdef numpy.ndarray weights_ndarray

    +346: 		cdef int i, j, n = X_ndarray.shape[0], d = X_ndarray.shape[1]

      __pyx_v_n = (__pyx_v_X_ndarray->dimensions[0]);
      __pyx_v_d = (__pyx_v_X_ndarray->dimensions[1]);

    +347: 		cdef double* X_ptr = <double*> X_ndarray.data

      __pyx_v_X_ptr = ((double *)__pyx_v_X_ndarray->data);

     348: 		cdef double dist

     349:

    +350: 		if weights is None:

      __pyx_t_5 = (__pyx_v_weights == Py_None);
      __pyx_t_6 = (__pyx_t_5 != 0);
      if (__pyx_t_6) {
    /* … */
        goto __pyx_L3;
      }

    +351: 			weights_ndarray = numpy.ones(n, dtype='float64')

        __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ones); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_weights_ndarray = ((PyArrayObject *)__pyx_t_2);
        __pyx_t_2 = 0;

     352: 		else:

    +353: 			weights_ndarray = numpy.array(weights, dtype='float64')

      /*else*/ {
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_weights);
        __Pyx_GIVEREF(__pyx_v_weights);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_weights);
        __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_n_s_float64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_weights_ndarray = ((PyArrayObject *)__pyx_t_3);
        __pyx_t_3 = 0;
      }
      __pyx_L3:;

     354:

    +355: 		cdef double* weights_ptr = <double*> weights_ndarray.data

      __pyx_v_weights_ptr = ((double *)__pyx_v_weights_ndarray->data);

     356:

    +357: 		if self.d == 0:

      __pyx_t_6 = ((__pyx_v_self->__pyx_base.d == 0) != 0);
      if (__pyx_t_6) {
    /* … */
      }

    +358: 			self.d = d

        __pyx_v_self->__pyx_base.d = __pyx_v_d;

    +359: 			self.centroids = numpy.zeros((self.k, d))

        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_d); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_4);
        __pyx_t_1 = 0;
        __pyx_t_4 = 0;
        __pyx_t_4 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        if (!__pyx_t_4) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL;
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GIVEREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_v_self->centroids);
        __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
        __pyx_v_self->centroids = ((PyArrayObject *)__pyx_t_3);
        __pyx_t_3 = 0;

    +360: 			self.centroids_ptr = <double*> self.centroids.data

        __pyx_v_self->centroids_ptr = ((double *)__pyx_v_self->centroids->data);

     361:

    +362: 			self.centroids = initialize_centroids(X, weights_ndarray, self.k, self.init)

        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_initialize_centroids); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = NULL;
        __pyx_t_8 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_8 = 1;
          }
        }
        __pyx_t_4 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_INCREF(__pyx_v_X);
        __Pyx_GIVEREF(__pyx_v_X);
        PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_X);
        __Pyx_INCREF(((PyObject *)__pyx_v_weights_ndarray));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_weights_ndarray));
        PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, ((PyObject *)__pyx_v_weights_ndarray));
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_8, __pyx_t_1);
        __Pyx_INCREF(__pyx_v_self->init);
        __Pyx_GIVEREF(__pyx_v_self->init);
        PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_8, __pyx_v_self->init);
        __pyx_t_1 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GIVEREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_v_self->centroids);
        __Pyx_DECREF(((PyObject *)__pyx_v_self->centroids));
        __pyx_v_self->centroids = ((PyArrayObject *)__pyx_t_3);
        __pyx_t_3 = 0;

    +363: 			self.centroids_ptr = <double*> self.centroids.data

        __pyx_v_self->centroids_ptr = ((double *)__pyx_v_self->centroids->data);

     364:

    +365: 			self.summary_sizes = <double*> calloc(self.k, sizeof(double))

        __pyx_v_self->summary_sizes = ((double *)calloc(__pyx_v_self->k, (sizeof(double))));

    +366: 			self.summary_weights = <double*> calloc(self.k*d, sizeof(double))

        __pyx_v_self->summary_weights = ((double *)calloc((__pyx_v_self->k * __pyx_v_d), (sizeof(double))));

    +367: 			memset(self.summary_sizes, 0 ,self.k*sizeof(double))

        memset(__pyx_v_self->summary_sizes, 0, (__pyx_v_self->k * (sizeof(double))));

    +368: 			memset(self.summary_weights, 0, self.k*d*sizeof(double))

        memset(__pyx_v_self->summary_weights, 0, ((__pyx_v_self->k * __pyx_v_d) * (sizeof(double))));

     369:

    +370: 		with nogil:

      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {
    /* … */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L7;
            }
            __pyx_L7:;
          }
      }

    +371: 			dist = self._summarize(X_ptr, weights_ptr, n)

            __pyx_v_dist = ((struct __pyx_vtabstruct_11pomegranate_6kmeans_Kmeans *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._summarize(((struct __pyx_obj_11pomegranate_4base_Model *)__pyx_v_self), __pyx_v_X_ptr, __pyx_v_weights_ptr, __pyx_v_n);
          }

     372:

    +373: 		return dist

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_3 = PyFloat_FromDouble(__pyx_v_dist); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L0;

     374:

    +375: 	cdef double _summarize(self, double* X, double* weights, int n) nogil:

    static double __pyx_f_11pomegranate_6kmeans_6Kmeans__summarize(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, double *__pyx_v_X, double *__pyx_v_weights, int __pyx_v_n) {
      int __pyx_v_i;
      int __pyx_v_j;
      int __pyx_v_l;
      int __pyx_v_y;
      int __pyx_v_k;
      int __pyx_v_d;
      double __pyx_v_min_dist;
      double __pyx_v_dist;
      double __pyx_v_total_dist;
      double *__pyx_v_summary_sizes;
      double *__pyx_v_summary_weights;
      double __pyx_r;
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("_summarize", 0);
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
    /* … */
      /* function exit code */
      __pyx_r = 0;
      __pyx_L0:;
      #ifdef WITH_THREAD
      PyGILState_Release(__pyx_gilstate_save);
      #endif
      return __pyx_r;
    }

    +376: 		cdef int i, j, l, y, k = self.k, d = self.d

      /*try:*/ {
        __pyx_t_1 = __pyx_v_self->k;
        __pyx_v_k = __pyx_t_1;
        __pyx_t_1 = __pyx_v_self->__pyx_base.d;
        __pyx_v_d = __pyx_t_1;
    /* … */
      /*finally:*/ {
        __pyx_L3_return: {
          #ifdef WITH_THREAD
          __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          goto __pyx_L0;
        }
      }

    +377: 		cdef double min_dist, dist, total_dist = 0.0

        __pyx_v_total_dist = 0.0;

    +378: 		cdef double* summary_sizes = <double*> calloc(k, sizeof(double))

        __pyx_v_summary_sizes = ((double *)calloc(__pyx_v_k, (sizeof(double))));

    +379: 		cdef double* summary_weights = <double*> calloc(k*d, sizeof(double))

        __pyx_v_summary_weights = ((double *)calloc((__pyx_v_k * __pyx_v_d), (sizeof(double))));

    +380: 		memset(summary_sizes, 0, k*sizeof(double))

        memset(__pyx_v_summary_sizes, 0, (__pyx_v_k * (sizeof(double))));

    +381: 		memset(summary_weights, 0, k*d*sizeof(double))

        memset(__pyx_v_summary_weights, 0, ((__pyx_v_k * __pyx_v_d) * (sizeof(double))));

     382:

    +383: 		for i in range(n):

        __pyx_t_1 = __pyx_v_n;
        for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
          __pyx_v_i = __pyx_t_2;

    +384: 			min_dist = INF

          __pyx_v_min_dist = Py_HUGE_VAL;

     385:

    +386: 			for j in range(k):

          __pyx_t_3 = __pyx_v_k;
          for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
            __pyx_v_j = __pyx_t_4;

    +387: 				dist = 0.0

            __pyx_v_dist = 0.0;

     388:

    +389: 				for l in range(d):

            __pyx_t_5 = __pyx_v_d;
            for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
              __pyx_v_l = __pyx_t_6;

    +390: 					dist += (self.centroids_ptr[j*d + l] - X[i*d + l]) ** 2.0

              __pyx_v_dist = (__pyx_v_dist + pow(((__pyx_v_self->centroids_ptr[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)]) - (__pyx_v_X[((__pyx_v_i * __pyx_v_d) + __pyx_v_l)])), 2.0));
            }

     391:

    +392: 				if dist < min_dist:

            __pyx_t_7 = ((__pyx_v_dist < __pyx_v_min_dist) != 0);
            if (__pyx_t_7) {
    /* … */
            }
          }

    +393: 					min_dist = dist

              __pyx_v_min_dist = __pyx_v_dist;

    +394: 					y = j

              __pyx_v_y = __pyx_v_j;

     395:

    +396: 			total_dist += min_dist

          __pyx_v_total_dist = (__pyx_v_total_dist + __pyx_v_min_dist);

    +397: 			summary_sizes[y] += weights[i]

          __pyx_t_3 = __pyx_v_y;
          (__pyx_v_summary_sizes[__pyx_t_3]) = ((__pyx_v_summary_sizes[__pyx_t_3]) + (__pyx_v_weights[__pyx_v_i]));

     398:

    +399: 			for l in range(d):

          __pyx_t_3 = __pyx_v_d;
          for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
            __pyx_v_l = __pyx_t_4;

    +400: 				summary_weights[y*d + l] += X[i*d + l] * weights[i]

            __pyx_t_5 = ((__pyx_v_y * __pyx_v_d) + __pyx_v_l);
            (__pyx_v_summary_weights[__pyx_t_5]) = ((__pyx_v_summary_weights[__pyx_t_5]) + ((__pyx_v_X[((__pyx_v_i * __pyx_v_d) + __pyx_v_l)]) * (__pyx_v_weights[__pyx_v_i])));
          }
        }

     401:

    +402: 		with gil:

        {
            #ifdef WITH_THREAD
            PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
            #endif
            /*try:*/ {
    /* … */
            /*finally:*/ {
              /*normal exit:*/{
                #ifdef WITH_THREAD
                PyGILState_Release(__pyx_gilstate_save);
                #endif
                goto __pyx_L17;
              }
              __pyx_L17:;
            }
        }

    +403: 			for j in range(k):

              __pyx_t_1 = __pyx_v_k;
              for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
                __pyx_v_j = __pyx_t_2;

    +404: 				self.summary_sizes[j] += summary_sizes[j]

                __pyx_t_3 = __pyx_v_j;
                (__pyx_v_self->summary_sizes[__pyx_t_3]) = ((__pyx_v_self->summary_sizes[__pyx_t_3]) + (__pyx_v_summary_sizes[__pyx_v_j]));

     405:

    +406: 				for l in range(d):

                __pyx_t_3 = __pyx_v_d;
                for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
                  __pyx_v_l = __pyx_t_4;

    +407: 					self.summary_weights[j*d + l] += summary_weights[j*d + l]

                  __pyx_t_5 = ((__pyx_v_j * __pyx_v_d) + __pyx_v_l);
                  (__pyx_v_self->summary_weights[__pyx_t_5]) = ((__pyx_v_self->summary_weights[__pyx_t_5]) + (__pyx_v_summary_weights[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)]));
                }
              }
            }

     408:

    +409: 		free(summary_sizes)

        free(__pyx_v_summary_sizes);

    +410: 		free(summary_weights)

        free(__pyx_v_summary_weights);

    +411: 		return total_dist

        __pyx_r = __pyx_v_total_dist;
        goto __pyx_L3_return;
      }

     412:

    +413: 	def from_summaries(self, double inertia=0.0):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_11from_summaries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_11from_summaries(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      double __pyx_v_inertia;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("from_summaries (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_inertia,0};
        PyObject* values[1] = {0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_inertia);
              if (value) { values[0] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_summaries") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          switch (PyTuple_GET_SIZE(__pyx_args)) {
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        if (values[0]) {
          __pyx_v_inertia = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_inertia == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        } else {
          __pyx_v_inertia = ((double)0.0);
        }
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("from_summaries", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.from_summaries", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_10from_summaries(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), __pyx_v_inertia);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_10from_summaries(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, double __pyx_v_inertia) {
      int __pyx_v_l;
      int __pyx_v_j;
      int __pyx_v_k;
      int __pyx_v_d;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("from_summaries", 0);
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +414: 		if self.d == 0:

      __pyx_t_1 = ((__pyx_v_self->__pyx_base.d == 0) != 0);
      if (__pyx_t_1) {
    /* … */
      }

    +415: 			return

        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

     416:

    +417: 		cdef int l, j, k = self.k, d = self.d

      __pyx_t_2 = __pyx_v_self->k;
      __pyx_v_k = __pyx_t_2;
      __pyx_t_2 = __pyx_v_self->__pyx_base.d;
      __pyx_v_d = __pyx_t_2;

     418:

    +419: 		with nogil:

      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          #endif
          /*try:*/ {
    /* … */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L6;
            }
            __pyx_L6:;
          }
      }

    +420: 			for j in range(k):

            __pyx_t_2 = __pyx_v_k;
            for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
              __pyx_v_j = __pyx_t_3;

    +421: 				for l in range(d):

              __pyx_t_4 = __pyx_v_d;
              for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
                __pyx_v_l = __pyx_t_5;

    +422: 					self.centroids_ptr[j*d + l] = \

                (__pyx_v_self->centroids_ptr[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)]) = ((__pyx_v_inertia * (__pyx_v_self->centroids_ptr[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)])) + (((1.0 - __pyx_v_inertia) * (__pyx_v_self->summary_weights[((__pyx_v_j * __pyx_v_d) + __pyx_v_l)])) / (__pyx_v_self->summary_sizes[__pyx_v_j])));
              }
            }

     423: 						inertia * self.centroids_ptr[j*d + l] \

     424: 						+ (1-inertia) * self.summary_weights[j*d + l] \

     425: 						/ self.summary_sizes[j] \

     426:

    +427: 			memset(self.summary_sizes, 0, self.k * sizeof(int))

            memset(__pyx_v_self->summary_sizes, 0, (__pyx_v_self->k * (sizeof(int))));

    +428: 			memset(self.summary_weights, 0, self.k * self.d * sizeof(int))

            memset(__pyx_v_self->summary_weights, 0, ((__pyx_v_self->k * __pyx_v_self->__pyx_base.d) * (sizeof(int))));
          }

     429:

    +430: 	def clear_summaries(self):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_13clear_summaries(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_13clear_summaries(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("clear_summaries (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_12clear_summaries(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_12clear_summaries(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("clear_summaries", 0);
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +431: 		memset(self.summary_sizes, 0, self.k*sizeof(int))

      memset(__pyx_v_self->summary_sizes, 0, (__pyx_v_self->k * (sizeof(int))));

    +432: 		memset(self.summary_weights, 0, self.k*self.d*sizeof(int))

      memset(__pyx_v_self->summary_weights, 0, ((__pyx_v_self->k * __pyx_v_self->__pyx_base.d) * (sizeof(int))));

     433:

    +434: 	def to_json(self, separators=(',', ' : '), indent=4):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_15to_json(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_15to_json(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_separators = 0;
      PyObject *__pyx_v_indent = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("to_json (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_separators,&__pyx_n_s_indent,0};
        PyObject* values[2] = {0,0};
        values[0] = ((PyObject *)__pyx_tuple__5);
        values[1] = ((PyObject *)__pyx_int_4);
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_separators);
              if (value) { values[0] = value; kw_args--; }
            }
            case  1:
            if (kw_args > 0) {
              PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_indent);
              if (value) { values[1] = value; kw_args--; }
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "to_json") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
          }
        } else {
          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;
          }
        }
        __pyx_v_separators = values[0];
        __pyx_v_indent = values[1];
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("to_json", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_L3_error:;
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.to_json", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_14to_json(((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_v_self), __pyx_v_separators, __pyx_v_indent);

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_14to_json(struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_self, PyObject *__pyx_v_separators, PyObject *__pyx_v_indent) {
      PyObject *__pyx_v_model = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("to_json", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.to_json", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_model);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__5 = PyTuple_Pack(2, __pyx_kp_s__3, __pyx_kp_s__4); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_tuple__5);
      __Pyx_GIVEREF(__pyx_tuple__5);

     435: 		model = {

    +436: 					'class' : 'Kmeans',

      __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_class, __pyx_n_s_Kmeans) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    +437: 					'k' : self.k,

      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_k, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +438: 					'centroids'  : self.centroids.tolist()

      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->centroids), __pyx_n_s_tolist); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_centroids, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_model = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

     439: 				}

     440:

    +441: 		return json.dumps(model, separators=separators, indent=indent)

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_json); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dumps); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_model);
      __Pyx_GIVEREF(__pyx_v_model);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_model);
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_separators, __pyx_v_separators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_indent, __pyx_v_indent) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

     442:

    +443: 	@classmethod

      __pyx_t_2 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem((PyObject *)__pyx_ptype_11pomegranate_6kmeans_Kmeans->tp_dict, __pyx_n_s_from_json, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      PyType_Modified(__pyx_ptype_11pomegranate_6kmeans_Kmeans);

    +444: 	def from_json(cls, s):

    /* Python wrapper */
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_17from_json(PyObject *__pyx_v_cls, PyObject *__pyx_v_s); /*proto*/
    static PyObject *__pyx_pw_11pomegranate_6kmeans_6Kmeans_17from_json(PyObject *__pyx_v_cls, PyObject *__pyx_v_s) {
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("from_json (wrapper)", 0);
      __pyx_r = __pyx_pf_11pomegranate_6kmeans_6Kmeans_16from_json(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_s));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_11pomegranate_6kmeans_6Kmeans_16from_json(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_s) {
      PyObject *__pyx_v_d = NULL;
      struct __pyx_obj_11pomegranate_6kmeans_Kmeans *__pyx_v_model = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("from_json", 0);
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("pomegranate.kmeans.Kmeans.from_json", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_d);
      __Pyx_XDECREF((PyObject *)__pyx_v_model);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_11pomegranate_6kmeans_Kmeans, __pyx_n_s_from_json); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);

    +445: 		d = json.loads(s)

      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_json); 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);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_loads); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
        __Pyx_INCREF(__pyx_v_s);
        __Pyx_GIVEREF(__pyx_v_s);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_s);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_d = __pyx_t_1;
      __pyx_t_1 = 0;

    +446: 		model = Kmeans(d['k'], d['centroids'])

      __pyx_t_1 = PyObject_GetItem(__pyx_v_d, __pyx_n_s_k); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyObject_GetItem(__pyx_v_d, __pyx_n_s_centroids); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(2); 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_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_11pomegranate_6kmeans_Kmeans), __pyx_t_4, NULL); 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_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_model = ((struct __pyx_obj_11pomegranate_6kmeans_Kmeans *)__pyx_t_3);
      __pyx_t_3 = 0;

    +447: 		return model

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(((PyObject *)__pyx_v_model));
      __pyx_r = ((PyObject *)__pyx_v_model);
      goto __pyx_L0;