diff --git a/sklearn/cluster/_k_means.c b/sklearn/cluster/_k_means.c index 7ab4ae92a24ff..bc2cced8573c8 100644 --- a/sklearn/cluster/_k_means.c +++ b/sklearn/cluster/_k_means.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.19.1 on Wed Oct 9 22:31:47 2013 */ +/* Generated by Cython 0.20 on Thu Feb 6 13:19:03 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -19,6 +19,7 @@ #elif PY_VERSION_HEX < 0x02040000 #error Cython requires Python 2.4+. #else +#define CYTHON_ABI "0_20" #include /* For offsetof */ #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) @@ -53,6 +54,9 @@ #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif +#if CYTHON_COMPILING_IN_PYPY +#define Py_OptimizeFlag 0 +#endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX @@ -60,7 +64,7 @@ #define PY_FORMAT_SIZE_T "" #define CYTHON_FORMAT_SSIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) + #define PyInt_AsSsize_t(o) __Pyx_PyInt_As_int(o) #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ (PyErr_Format(PyExc_TypeError, \ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ @@ -113,12 +117,14 @@ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type #endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 +#if PY_VERSION_HEX < 0x02060000 #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") #endif #if PY_MAJOR_VERSION >= 3 @@ -131,19 +137,38 @@ #if PY_VERSION_HEX < 0x02060000 #define Py_TPFLAGS_HAVE_VERSION_TAG 0 #endif +#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT) + #define Py_TPFLAGS_IS_ABSTRACT 0 +#endif +#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE) + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#define __Pyx_PyUnicode_Concat(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \ + PyNumber_Add(a, b) : PyUnicode_Concat(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type @@ -176,7 +201,7 @@ #else #define __Pyx_PyBaseString_Check(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj) || \ PyString_Check(obj) || PyUnicode_Check(obj)) - #define __Pyx_PyBaseString_CheckExact(obj) (Py_TYPE(obj) == &PyBaseString_Type) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) @@ -201,6 +226,7 @@ #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject @@ -264,7 +290,7 @@ #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ - #elif defined(_MSC_VER) + #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict @@ -344,8 +370,20 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) ( \ + (sizeof(type) < sizeof(Py_ssize_t)) || \ + (sizeof(type) > sizeof(Py_ssize_t) && \ + likely(v < (type)PY_SSIZE_T_MAX || \ + v == (type)PY_SSIZE_T_MAX) && \ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN || \ + v == (type)PY_SSIZE_T_MIN))) || \ + (sizeof(type) == sizeof(Py_ssize_t) && \ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX || \ + v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); @@ -356,9 +394,11 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif +#define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromUString(s) __Pyx_PyObject_FromString((char*)s) #define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((char*)s) +#define __Pyx_PyByteArray_FromUString(s) __Pyx_PyByteArray_FromString((char*)s) #define __Pyx_PyStr_FromUString(s) __Pyx_PyStr_FromString((char*)s) #define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((char*)s) #if PY_MAJOR_VERSION < 3 @@ -380,7 +420,6 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #if CYTHON_COMPILING_IN_CPYTHON #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else @@ -389,7 +428,7 @@ static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; -static int __Pyx_init_sys_getdefaultencoding_params() { +static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys = NULL; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; @@ -414,7 +453,7 @@ static int __Pyx_init_sys_getdefaultencoding_params() { if (ascii_chars_b == NULL || strncmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, - "This module compiled with c_string_encoding=ascii, but default encoding '%s' is not a superset of ascii.", + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } @@ -438,7 +477,7 @@ static int __Pyx_init_sys_getdefaultencoding_params() { #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; -static int __Pyx_init_sys_getdefaultencoding_params() { +static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys = NULL; PyObject* default_encoding = NULL; char* default_encoding_c; @@ -509,7 +548,7 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "_k_means.pyx", - "numpy.pxd", + "__init__.pxd", "type.pxd", }; #define IS_UNSIGNED(type) (((type) -1) > 0) @@ -548,7 +587,7 @@ typedef struct { } __Pyx_BufFmt_Context; -/* "numpy.pxd":723 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":723 * # in Cython to enable them only on the right systems. * * ctypedef npy_int8 int8_t # <<<<<<<<<<<<<< @@ -557,7 +596,7 @@ typedef struct { */ typedef npy_int8 __pyx_t_5numpy_int8_t; -/* "numpy.pxd":724 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":724 * * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t # <<<<<<<<<<<<<< @@ -566,7 +605,7 @@ typedef npy_int8 __pyx_t_5numpy_int8_t; */ typedef npy_int16 __pyx_t_5numpy_int16_t; -/* "numpy.pxd":725 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":725 * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t # <<<<<<<<<<<<<< @@ -575,7 +614,7 @@ typedef npy_int16 __pyx_t_5numpy_int16_t; */ typedef npy_int32 __pyx_t_5numpy_int32_t; -/* "numpy.pxd":726 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":726 * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t * ctypedef npy_int64 int64_t # <<<<<<<<<<<<<< @@ -584,7 +623,7 @@ typedef npy_int32 __pyx_t_5numpy_int32_t; */ typedef npy_int64 __pyx_t_5numpy_int64_t; -/* "numpy.pxd":730 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":730 * #ctypedef npy_int128 int128_t * * ctypedef npy_uint8 uint8_t # <<<<<<<<<<<<<< @@ -593,7 +632,7 @@ typedef npy_int64 __pyx_t_5numpy_int64_t; */ typedef npy_uint8 __pyx_t_5numpy_uint8_t; -/* "numpy.pxd":731 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":731 * * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t # <<<<<<<<<<<<<< @@ -602,7 +641,7 @@ typedef npy_uint8 __pyx_t_5numpy_uint8_t; */ typedef npy_uint16 __pyx_t_5numpy_uint16_t; -/* "numpy.pxd":732 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":732 * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t # <<<<<<<<<<<<<< @@ -611,7 +650,7 @@ typedef npy_uint16 __pyx_t_5numpy_uint16_t; */ typedef npy_uint32 __pyx_t_5numpy_uint32_t; -/* "numpy.pxd":733 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":733 * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t * ctypedef npy_uint64 uint64_t # <<<<<<<<<<<<<< @@ -620,7 +659,7 @@ typedef npy_uint32 __pyx_t_5numpy_uint32_t; */ typedef npy_uint64 __pyx_t_5numpy_uint64_t; -/* "numpy.pxd":737 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":737 * #ctypedef npy_uint128 uint128_t * * ctypedef npy_float32 float32_t # <<<<<<<<<<<<<< @@ -629,7 +668,7 @@ typedef npy_uint64 __pyx_t_5numpy_uint64_t; */ typedef npy_float32 __pyx_t_5numpy_float32_t; -/* "numpy.pxd":738 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":738 * * ctypedef npy_float32 float32_t * ctypedef npy_float64 float64_t # <<<<<<<<<<<<<< @@ -638,7 +677,7 @@ typedef npy_float32 __pyx_t_5numpy_float32_t; */ typedef npy_float64 __pyx_t_5numpy_float64_t; -/* "numpy.pxd":747 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":747 * # The int types are mapped a bit surprising -- * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t # <<<<<<<<<<<<<< @@ -647,7 +686,7 @@ typedef npy_float64 __pyx_t_5numpy_float64_t; */ typedef npy_long __pyx_t_5numpy_int_t; -/* "numpy.pxd":748 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":748 * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t * ctypedef npy_longlong long_t # <<<<<<<<<<<<<< @@ -656,7 +695,7 @@ typedef npy_long __pyx_t_5numpy_int_t; */ typedef npy_longlong __pyx_t_5numpy_long_t; -/* "numpy.pxd":749 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":749 * ctypedef npy_long int_t * ctypedef npy_longlong long_t * ctypedef npy_longlong longlong_t # <<<<<<<<<<<<<< @@ -665,7 +704,7 @@ typedef npy_longlong __pyx_t_5numpy_long_t; */ typedef npy_longlong __pyx_t_5numpy_longlong_t; -/* "numpy.pxd":751 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":751 * ctypedef npy_longlong longlong_t * * ctypedef npy_ulong uint_t # <<<<<<<<<<<<<< @@ -674,7 +713,7 @@ typedef npy_longlong __pyx_t_5numpy_longlong_t; */ typedef npy_ulong __pyx_t_5numpy_uint_t; -/* "numpy.pxd":752 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":752 * * ctypedef npy_ulong uint_t * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< @@ -683,7 +722,7 @@ typedef npy_ulong __pyx_t_5numpy_uint_t; */ typedef npy_ulonglong __pyx_t_5numpy_ulong_t; -/* "numpy.pxd":753 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":753 * ctypedef npy_ulong uint_t * ctypedef npy_ulonglong ulong_t * ctypedef npy_ulonglong ulonglong_t # <<<<<<<<<<<<<< @@ -692,7 +731,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulong_t; */ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; -/* "numpy.pxd":755 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":755 * ctypedef npy_ulonglong ulonglong_t * * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< @@ -701,7 +740,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; */ typedef npy_intp __pyx_t_5numpy_intp_t; -/* "numpy.pxd":756 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":756 * * ctypedef npy_intp intp_t * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< @@ -710,7 +749,7 @@ typedef npy_intp __pyx_t_5numpy_intp_t; */ typedef npy_uintp __pyx_t_5numpy_uintp_t; -/* "numpy.pxd":758 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":758 * ctypedef npy_uintp uintp_t * * ctypedef npy_double float_t # <<<<<<<<<<<<<< @@ -719,7 +758,7 @@ typedef npy_uintp __pyx_t_5numpy_uintp_t; */ typedef npy_double __pyx_t_5numpy_float_t; -/* "numpy.pxd":759 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":759 * * ctypedef npy_double float_t * ctypedef npy_double double_t # <<<<<<<<<<<<<< @@ -728,7 +767,7 @@ typedef npy_double __pyx_t_5numpy_float_t; */ typedef npy_double __pyx_t_5numpy_double_t; -/* "numpy.pxd":760 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":760 * ctypedef npy_double float_t * ctypedef npy_double double_t * ctypedef npy_longdouble longdouble_t # <<<<<<<<<<<<<< @@ -777,7 +816,7 @@ typedef __pyx_t_5numpy_int32_t __pyx_t_7sklearn_7cluster_8_k_means_INT; /*--- Type declarations ---*/ -/* "numpy.pxd":762 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":762 * ctypedef npy_longdouble longdouble_t * * ctypedef npy_cfloat cfloat_t # <<<<<<<<<<<<<< @@ -786,7 +825,7 @@ typedef __pyx_t_5numpy_int32_t __pyx_t_7sklearn_7cluster_8_k_means_INT; */ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; -/* "numpy.pxd":763 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":763 * * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< @@ -795,7 +834,7 @@ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; */ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; -/* "numpy.pxd":764 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":764 * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t * ctypedef npy_clongdouble clongdouble_t # <<<<<<<<<<<<<< @@ -804,7 +843,7 @@ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; */ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; -/* "numpy.pxd":766 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":766 * ctypedef npy_clongdouble clongdouble_t * * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< @@ -863,6 +902,14 @@ typedef npy_cdouble __pyx_t_5numpy_complex_t; #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif /* CYTHON_REFNANNY */ +#define __Pyx_XDECREF_SET(r, v) do { \ + PyObject *tmp = (PyObject *) r; \ + r = v; __Pyx_XDECREF(tmp); \ + } while (0) +#define __Pyx_DECREF_SET(r, v) do { \ + PyObject *tmp = (PyObject *) r; \ + r = v; __Pyx_DECREF(tmp); \ + } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) @@ -971,15 +1018,34 @@ static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); -#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) #define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename); /*proto*/ + int lineno, const char *filename, + int full_traceback); /*proto*/ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ @@ -990,29 +1056,12 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ -#define __Pyx_GetItemInt(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i, is_list, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -#define __Pyx_GetItemInt_List(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, - int is_list, int wraparound, int boundscheck); +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ +#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) \ __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) static CYTHON_INLINE int __Pyx_PyObject_SetSlice( @@ -1020,10 +1069,11 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( PyObject** py_start, PyObject** py_stop, PyObject** py_slice, int has_cstart, int has_cstop, int wraparound); -#define __Pyx_SetItemInt(o, i, v, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_SetItemInt_Fast(o, i, v, is_list, wraparound, boundscheck) : \ - __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) +#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) : \ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v))) static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v); static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list, int wraparound, int boundscheck); @@ -1043,10 +1093,6 @@ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); -static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ - static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /*proto*/ typedef struct { @@ -1076,11 +1122,21 @@ static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1}; static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /*proto*/ -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int32(npy_int32); +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value); + +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *); + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int32(npy_int32 value); -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); -static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_from_py_Py_intptr_t(PyObject *); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value); + +static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_As_Py_intptr_t(PyObject *); #if CYTHON_CCOMPLEX #ifdef __cplusplus @@ -1094,7 +1150,7 @@ static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_from_py_Py_intptr_t(PyObject *); #define __Pyx_CREAL(z) ((z).real) #define __Pyx_CIMAG(z) ((z).imag) #endif -#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX +#if (defined(_WIN32) || defined(__clang__)) && defined(__cplusplus) && CYTHON_CCOMPLEX #define __Pyx_SET_CREAL(z,x) ((z).real(x)) #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) #else @@ -1180,37 +1236,7 @@ static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(do #endif #endif -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); static int __Pyx_check_binary_version(void); @@ -1283,6 +1309,8 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, cha static void (*__pyx_f_7sklearn_5utils_11sparsefuncs_add_row_csr)(PyArrayObject *, PyArrayObject *, PyArrayObject *, int, PyArrayObject *); /*proto*/ /* Module declarations from 'sklearn.cluster._k_means' */ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array_L1(PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr_L1(PyObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array(PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr(PyObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, int __pyx_skip_dispatch); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE = { "DOUBLE", NULL, sizeof(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE), { 0 }, 0, 'R', 0, 0 }; @@ -1297,205 +1325,211 @@ static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_counts, PyArrayObject *__pyx_v_nearest_center, PyArrayObject *__pyx_v_old_center, int __pyx_v_compute_squared_diff); /* proto */ -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, int __pyx_v_n_clusters, PyArrayObject *__pyx_v_distances); /* proto */ -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, PyObject *__pyx_v_n_clusters, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array_L1(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr_L1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_assign_labels_array(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_assign_labels_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_mini_batch_update_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_counts, PyArrayObject *__pyx_v_nearest_center, PyArrayObject *__pyx_v_old_center, int __pyx_v_compute_squared_diff); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_10_centers_dense(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, int __pyx_v_n_clusters, PyArrayObject *__pyx_v_distances); /* proto */ +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_12_centers_sparse(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, PyObject *__pyx_v_n_clusters, PyArrayObject *__pyx_v_distances); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ -static char __pyx_k_1[] = "compute_squared_diff"; -static char __pyx_k_7[] = "ndarray is not C contiguous"; -static char __pyx_k_9[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_11[] = "Non-native byte order not supported"; -static char __pyx_k_13[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_14[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_17[] = "Format string allocated too short."; -static char __pyx_k_19[] = "scipy.sparse"; -static char __pyx_k_20[] = "*"; -static char __pyx_k_21[] = "utils.extmath"; -static char __pyx_k_22[] = "utils.fixes"; -static char __pyx_k_25[] = "_mini_batch_update_csr"; -static char __pyx_k_26[] = "/home/larsb/src/scikit-learn/sklearn/cluster/_k_means.pyx"; -static char __pyx_k_27[] = "sklearn.cluster._k_means"; -static char __pyx_k_28[] = "n_samples_in_cluster"; -static char __pyx_k__B[] = "B"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__X[] = "X"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__c[] = "c"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__j[] = "j"; -static char __pyx_k__k[] = "k"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__sp[] = "sp"; -static char __pyx_k__data[] = "data"; -static char __pyx_k__norm[] = "norm"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__where[] = "where"; -static char __pyx_k__zeros[] = "zeros"; -static char __pyx_k__X_data[] = "X_data"; -static char __pyx_k__counts[] = "counts"; -static char __pyx_k__indptr[] = "indptr"; -static char __pyx_k__labels[] = "labels"; -static char __pyx_k__argsort[] = "argsort"; -static char __pyx_k__centers[] = "centers"; -static char __pyx_k__float64[] = "float64"; -static char __pyx_k__indices[] = "indices"; -static char __pyx_k__newaxis[] = "newaxis"; -static char __pyx_k__X_indptr[] = "X_indptr"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__bincount[] = "bincount"; -static char __pyx_k__X_indices[] = "X_indices"; -static char __pyx_k__distances[] = "distances"; -static char __pyx_k__enumerate[] = "enumerate"; -static char __pyx_k__minlength[] = "minlength"; -static char __pyx_k__n_samples[] = "n_samples"; -static char __pyx_k__new_count[] = "new_count"; -static char __pyx_k__old_count[] = "old_count"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k____import__[] = "__import__"; -static char __pyx_k__center_idx[] = "center_idx"; -static char __pyx_k__cluster_id[] = "cluster_id"; -static char __pyx_k__n_clusters[] = "n_clusters"; -static char __pyx_k__n_features[] = "n_features"; -static char __pyx_k__new_center[] = "new_center"; -static char __pyx_k__old_center[] = "old_center"; -static char __pyx_k__sample_idx[] = "sample_idx"; -static char __pyx_k__center_diff[] = "center_diff"; -static char __pyx_k__feature_idx[] = "feature_idx"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__squared_diff[] = "squared_diff"; -static char __pyx_k___centers_dense[] = "_centers_dense"; -static char __pyx_k__empty_clusters[] = "empty_clusters"; -static char __pyx_k__nearest_center[] = "nearest_center"; -static char __pyx_k____pyx_getbuffer[] = "__pyx_getbuffer"; -static char __pyx_k___centers_sparse[] = "_centers_sparse"; -static char __pyx_k__x_squared_norms[] = "x_squared_norms"; -static char __pyx_k__far_from_centers[] = "far_from_centers"; -static char __pyx_k____pyx_releasebuffer[] = "__pyx_releasebuffer"; -static PyObject *__pyx_n_s_1; -static PyObject *__pyx_kp_u_11; -static PyObject *__pyx_kp_u_13; -static PyObject *__pyx_kp_u_14; -static PyObject *__pyx_kp_u_17; -static PyObject *__pyx_n_s_19; -static PyObject *__pyx_n_s_20; -static PyObject *__pyx_n_s_21; -static PyObject *__pyx_n_s_22; -static PyObject *__pyx_n_s_25; -static PyObject *__pyx_kp_s_26; -static PyObject *__pyx_n_s_27; -static PyObject *__pyx_n_s_28; -static PyObject *__pyx_kp_u_7; -static PyObject *__pyx_kp_u_9; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s__X; -static PyObject *__pyx_n_s__X_data; -static PyObject *__pyx_n_s__X_indices; -static PyObject *__pyx_n_s__X_indptr; -static PyObject *__pyx_n_s____import__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____pyx_getbuffer; -static PyObject *__pyx_n_s____pyx_releasebuffer; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s___centers_dense; -static PyObject *__pyx_n_s___centers_sparse; -static PyObject *__pyx_n_s__argsort; -static PyObject *__pyx_n_s__bincount; -static PyObject *__pyx_n_s__c; -static PyObject *__pyx_n_s__center_diff; -static PyObject *__pyx_n_s__center_idx; -static PyObject *__pyx_n_s__centers; -static PyObject *__pyx_n_s__cluster_id; -static PyObject *__pyx_n_s__counts; -static PyObject *__pyx_n_s__data; -static PyObject *__pyx_n_s__distances; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__empty_clusters; -static PyObject *__pyx_n_s__enumerate; -static PyObject *__pyx_n_s__far_from_centers; -static PyObject *__pyx_n_s__feature_idx; -static PyObject *__pyx_n_s__float64; -static PyObject *__pyx_n_s__i; -static PyObject *__pyx_n_s__indices; -static PyObject *__pyx_n_s__indptr; -static PyObject *__pyx_n_s__j; -static PyObject *__pyx_n_s__k; -static PyObject *__pyx_n_s__labels; -static PyObject *__pyx_n_s__minlength; -static PyObject *__pyx_n_s__n_clusters; -static PyObject *__pyx_n_s__n_features; -static PyObject *__pyx_n_s__n_samples; -static PyObject *__pyx_n_s__nearest_center; -static PyObject *__pyx_n_s__new_center; -static PyObject *__pyx_n_s__new_count; -static PyObject *__pyx_n_s__newaxis; -static PyObject *__pyx_n_s__norm; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__old_center; -static PyObject *__pyx_n_s__old_count; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__sample_idx; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__sp; -static PyObject *__pyx_n_s__squared_diff; -static PyObject *__pyx_n_s__where; -static PyObject *__pyx_n_s__x_squared_norms; -static PyObject *__pyx_n_s__zeros; +static char __pyx_k_B[] = "B"; +static char __pyx_k_H[] = "H"; +static char __pyx_k_I[] = "I"; +static char __pyx_k_L[] = "L"; +static char __pyx_k_O[] = "O"; +static char __pyx_k_Q[] = "Q"; +static char __pyx_k_X[] = "X"; +static char __pyx_k_b[] = "b"; +static char __pyx_k_c[] = "c"; +static char __pyx_k_d[] = "d"; +static char __pyx_k_f[] = "f"; +static char __pyx_k_g[] = "g"; +static char __pyx_k_h[] = "h"; +static char __pyx_k_i[] = "i"; +static char __pyx_k_j[] = "j"; +static char __pyx_k_k[] = "k"; +static char __pyx_k_l[] = "l"; +static char __pyx_k_q[] = "q"; +static char __pyx_k_Zd[] = "Zd"; +static char __pyx_k_Zf[] = "Zf"; +static char __pyx_k_Zg[] = "Zg"; +static char __pyx_k_np[] = "np"; +static char __pyx_k_sp[] = "sp"; +static char __pyx_k__12[] = "*"; +static char __pyx_k_abs[] = "abs"; +static char __pyx_k_sum[] = "sum"; +static char __pyx_k_data[] = "data"; +static char __pyx_k_main[] = "__main__"; +static char __pyx_k_norm[] = "norm"; +static char __pyx_k_test[] = "__test__"; +static char __pyx_k_dtype[] = "dtype"; +static char __pyx_k_numpy[] = "numpy"; +static char __pyx_k_range[] = "range"; +static char __pyx_k_shape[] = "shape"; +static char __pyx_k_where[] = "where"; +static char __pyx_k_zeros[] = "zeros"; +static char __pyx_k_X_data[] = "X_data"; +static char __pyx_k_counts[] = "counts"; +static char __pyx_k_import[] = "__import__"; +static char __pyx_k_indptr[] = "indptr"; +static char __pyx_k_labels[] = "labels"; +static char __pyx_k_argsort[] = "argsort"; +static char __pyx_k_centers[] = "centers"; +static char __pyx_k_float64[] = "float64"; +static char __pyx_k_indices[] = "indices"; +static char __pyx_k_newaxis[] = "newaxis"; +static char __pyx_k_X_indptr[] = "X_indptr"; +static char __pyx_k_bincount[] = "bincount"; +static char __pyx_k_X_indices[] = "X_indices"; +static char __pyx_k_distances[] = "distances"; +static char __pyx_k_enumerate[] = "enumerate"; +static char __pyx_k_minlength[] = "minlength"; +static char __pyx_k_n_samples[] = "n_samples"; +static char __pyx_k_new_count[] = "new_count"; +static char __pyx_k_old_count[] = "old_count"; +static char __pyx_k_ValueError[] = "ValueError"; +static char __pyx_k_center_idx[] = "center_idx"; +static char __pyx_k_cluster_id[] = "cluster_id"; +static char __pyx_k_n_clusters[] = "n_clusters"; +static char __pyx_k_n_features[] = "n_features"; +static char __pyx_k_new_center[] = "new_center"; +static char __pyx_k_old_center[] = "old_center"; +static char __pyx_k_sample_idx[] = "sample_idx"; +static char __pyx_k_center_diff[] = "center_diff"; +static char __pyx_k_feature_idx[] = "feature_idx"; +static char __pyx_k_utils_fixes[] = "utils.fixes"; +static char __pyx_k_RuntimeError[] = "RuntimeError"; +static char __pyx_k_scipy_sparse[] = "scipy.sparse"; +static char __pyx_k_squared_diff[] = "squared_diff"; +static char __pyx_k_centers_dense[] = "_centers_dense"; +static char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; +static char __pyx_k_utils_extmath[] = "utils.extmath"; +static char __pyx_k_centers_sparse[] = "_centers_sparse"; +static char __pyx_k_empty_clusters[] = "empty_clusters"; +static char __pyx_k_nearest_center[] = "nearest_center"; +static char __pyx_k_x_squared_norms[] = "x_squared_norms"; +static char __pyx_k_far_from_centers[] = "far_from_centers"; +static char __pyx_k_pyx_releasebuffer[] = "__pyx_releasebuffer"; +static char __pyx_k_compute_squared_diff[] = "compute_squared_diff"; +static char __pyx_k_n_samples_in_cluster[] = "n_samples_in_cluster"; +static char __pyx_k_mini_batch_update_csr[] = "_mini_batch_update_csr"; +static char __pyx_k_sklearn_cluster__k_means[] = "sklearn.cluster._k_means"; +static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous"; +static char __pyx_k_Volumes_LocalDataHD_LocalScratc[] = "/Volumes/LocalDataHD/LocalScratchData/scikit-learn/sklearn/cluster/_k_means.pyx"; +static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)"; +static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd"; +static char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported"; +static char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous"; +static char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short."; +static PyObject *__pyx_kp_u_Format_string_allocated_too_shor; +static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2; +static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor; +static PyObject *__pyx_n_s_RuntimeError; +static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_kp_s_Volumes_LocalDataHD_LocalScratc; +static PyObject *__pyx_n_s_X; +static PyObject *__pyx_n_s_X_data; +static PyObject *__pyx_n_s_X_indices; +static PyObject *__pyx_n_s_X_indptr; +static PyObject *__pyx_n_s__12; +static PyObject *__pyx_n_s_abs; +static PyObject *__pyx_n_s_argsort; +static PyObject *__pyx_n_s_bincount; +static PyObject *__pyx_n_s_c; +static PyObject *__pyx_n_s_center_diff; +static PyObject *__pyx_n_s_center_idx; +static PyObject *__pyx_n_s_centers; +static PyObject *__pyx_n_s_centers_dense; +static PyObject *__pyx_n_s_centers_sparse; +static PyObject *__pyx_n_s_cluster_id; +static PyObject *__pyx_n_s_compute_squared_diff; +static PyObject *__pyx_n_s_counts; +static PyObject *__pyx_n_s_data; +static PyObject *__pyx_n_s_distances; +static PyObject *__pyx_n_s_dtype; +static PyObject *__pyx_n_s_empty_clusters; +static PyObject *__pyx_n_s_enumerate; +static PyObject *__pyx_n_s_far_from_centers; +static PyObject *__pyx_n_s_feature_idx; +static PyObject *__pyx_n_s_float64; +static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_indices; +static PyObject *__pyx_n_s_indptr; +static PyObject *__pyx_n_s_j; +static PyObject *__pyx_n_s_k; +static PyObject *__pyx_n_s_labels; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_mini_batch_update_csr; +static PyObject *__pyx_n_s_minlength; +static PyObject *__pyx_n_s_n_clusters; +static PyObject *__pyx_n_s_n_features; +static PyObject *__pyx_n_s_n_samples; +static PyObject *__pyx_n_s_n_samples_in_cluster; +static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous; +static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou; +static PyObject *__pyx_n_s_nearest_center; +static PyObject *__pyx_n_s_new_center; +static PyObject *__pyx_n_s_new_count; +static PyObject *__pyx_n_s_newaxis; +static PyObject *__pyx_n_s_norm; +static PyObject *__pyx_n_s_np; +static PyObject *__pyx_n_s_numpy; +static PyObject *__pyx_n_s_old_center; +static PyObject *__pyx_n_s_old_count; +static PyObject *__pyx_n_s_pyx_getbuffer; +static PyObject *__pyx_n_s_pyx_releasebuffer; +static PyObject *__pyx_n_s_range; +static PyObject *__pyx_n_s_sample_idx; +static PyObject *__pyx_n_s_scipy_sparse; +static PyObject *__pyx_n_s_shape; +static PyObject *__pyx_n_s_sklearn_cluster__k_means; +static PyObject *__pyx_n_s_sp; +static PyObject *__pyx_n_s_squared_diff; +static PyObject *__pyx_n_s_sum; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd; +static PyObject *__pyx_n_s_utils_extmath; +static PyObject *__pyx_n_s_utils_fixes; +static PyObject *__pyx_n_s_where; +static PyObject *__pyx_n_s_x_squared_norms; +static PyObject *__pyx_n_s_zeros; +static PyObject *__pyx_float_0_; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_int_15; -static PyObject *__pyx_k_slice_2; -static PyObject *__pyx_k_slice_3; -static PyObject *__pyx_k_slice_4; -static PyObject *__pyx_k_slice_5; -static PyObject *__pyx_k_slice_6; -static PyObject *__pyx_k_tuple_8; -static PyObject *__pyx_k_tuple_10; -static PyObject *__pyx_k_tuple_12; -static PyObject *__pyx_k_tuple_15; -static PyObject *__pyx_k_tuple_16; -static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_tuple_23; -static PyObject *__pyx_k_tuple_29; -static PyObject *__pyx_k_tuple_31; -static PyObject *__pyx_k_codeobj_24; -static PyObject *__pyx_k_codeobj_30; -static PyObject *__pyx_k_codeobj_32; +static PyObject *__pyx_slice_; +static PyObject *__pyx_slice__2; +static PyObject *__pyx_slice__3; +static PyObject *__pyx_slice__4; +static PyObject *__pyx_slice__5; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_tuple__7; +static PyObject *__pyx_tuple__8; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__10; +static PyObject *__pyx_tuple__11; +static PyObject *__pyx_tuple__13; +static PyObject *__pyx_tuple__15; +static PyObject *__pyx_tuple__17; +static PyObject *__pyx_codeobj__14; +static PyObject *__pyx_codeobj__16; +static PyObject *__pyx_codeobj__18; /* "sklearn/cluster/_k_means.pyx":32 * @cython.wraparound(False) * @cython.cdivision(True) - * cpdef DOUBLE _assign_labels_array(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=1] x_squared_norms, - * np.ndarray[DOUBLE, ndim=2] centers, + * cpdef DOUBLE _assign_labels_array_L1(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] labels, */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array(PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array_L1(PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { unsigned int __pyx_v_n_clusters; - unsigned int __pyx_v_n_features; + CYTHON_UNUSED unsigned int __pyx_v_n_features; unsigned int __pyx_v_n_samples; unsigned int __pyx_v_sample_idx; unsigned int __pyx_v_center_idx; @@ -1503,64 +1537,40 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_inertia; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_min_dist; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_dist; - PyArrayObject *__pyx_v_center_squared_norms = 0; + PyObject *__pyx_v_sum = NULL; + PyObject *__pyx_v_abs = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_X; __Pyx_Buffer __pyx_pybuffer_X; - __Pyx_LocalBuf_ND __pyx_pybuffernd_center_squared_norms; - __Pyx_Buffer __pyx_pybuffer_center_squared_norms; __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; __Pyx_Buffer __pyx_pybuffer_centers; __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; __Pyx_Buffer __pyx_pybuffer_distances; __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; __Pyx_Buffer __pyx_pybuffer_labels; - __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; - __Pyx_Buffer __pyx_pybuffer_x_squared_norms; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyArrayObject *__pyx_t_6 = NULL; - int __pyx_t_7; + unsigned int __pyx_t_5; + unsigned int __pyx_t_6; + unsigned int __pyx_t_7; unsigned int __pyx_t_8; - unsigned int __pyx_t_9; - unsigned int __pyx_t_10; - long __pyx_t_11; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_t_9; + int __pyx_t_10; + int __pyx_t_11; unsigned int __pyx_t_12; - long __pyx_t_13; - unsigned int __pyx_t_14; - unsigned int __pyx_t_15; - unsigned int __pyx_t_16; - unsigned int __pyx_t_17; - long __pyx_t_18; - unsigned int __pyx_t_19; - long __pyx_t_20; - unsigned int __pyx_t_21; - unsigned int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - unsigned int __pyx_t_25; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_TraceDeclarations - __Pyx_RefNannySetupContext("_assign_labels_array", 0); - __Pyx_TraceCall("_assign_labels_array", __pyx_f[0], 32); - __pyx_pybuffer_center_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_center_squared_norms.refcount = 0; - __pyx_pybuffernd_center_squared_norms.data = NULL; - __pyx_pybuffernd_center_squared_norms.rcbuffer = &__pyx_pybuffer_center_squared_norms; + __Pyx_RefNannySetupContext("_assign_labels_array_L1", 0); + __Pyx_TraceCall("_assign_labels_array_L1", __pyx_f[0], 32); __pyx_pybuffer_X.pybuffer.buf = NULL; __pyx_pybuffer_X.refcount = 0; __pyx_pybuffernd_X.data = NULL; __pyx_pybuffernd_X.rcbuffer = &__pyx_pybuffer_X; - __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_x_squared_norms.refcount = 0; - __pyx_pybuffernd_x_squared_norms.data = NULL; - __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; __pyx_pybuffer_centers.pybuffer.buf = NULL; __pyx_pybuffer_centers.refcount = 0; __pyx_pybuffernd_centers.data = NULL; @@ -1578,11 +1588,6 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -1599,7 +1604,7 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; - /* "sklearn/cluster/_k_means.pyx":42 + /* "sklearn/cluster/_k_means.pyx":41 * """ * cdef: * unsigned int n_clusters = centers.shape[0] # <<<<<<<<<<<<<< @@ -1608,322 +1613,215 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ */ __pyx_v_n_clusters = (__pyx_v_centers->dimensions[0]); - /* "sklearn/cluster/_k_means.pyx":43 + /* "sklearn/cluster/_k_means.pyx":42 * cdef: * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] # <<<<<<<<<<<<<< * unsigned int n_samples = X.shape[0] - * unsigned int sample_idx, center_idx, feature_idx + * unsigned int sample_idx, center_idx */ __pyx_v_n_features = (__pyx_v_centers->dimensions[1]); - /* "sklearn/cluster/_k_means.pyx":44 + /* "sklearn/cluster/_k_means.pyx":43 * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] * unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< - * unsigned int sample_idx, center_idx, feature_idx + * unsigned int sample_idx, center_idx * unsigned int store_distances = 0 */ __pyx_v_n_samples = (__pyx_v_X->dimensions[0]); - /* "sklearn/cluster/_k_means.pyx":46 + /* "sklearn/cluster/_k_means.pyx":45 * unsigned int n_samples = X.shape[0] - * unsigned int sample_idx, center_idx, feature_idx + * unsigned int sample_idx, center_idx * unsigned int store_distances = 0 # <<<<<<<<<<<<<< - * unsigned int k * DOUBLE inertia = 0.0 + * DOUBLE min_dist */ __pyx_v_store_distances = 0; - /* "sklearn/cluster/_k_means.pyx":48 + /* "sklearn/cluster/_k_means.pyx":46 + * unsigned int sample_idx, center_idx * unsigned int store_distances = 0 - * unsigned int k * DOUBLE inertia = 0.0 # <<<<<<<<<<<<<< * DOUBLE min_dist * DOUBLE dist */ __pyx_v_inertia = 0.0; - /* "sklearn/cluster/_k_means.pyx":51 - * DOUBLE min_dist - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< - * n_clusters, dtype=np.float64) - * - */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __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 = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "sklearn/cluster/_k_means.pyx":52 - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( - * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< - * - * if n_samples == distances.shape[0]: - */ - __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_n_clusters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __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 = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - - /* "sklearn/cluster/_k_means.pyx":51 - * DOUBLE min_dist - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< - * n_clusters, dtype=np.float64) - * - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - - /* "sklearn/cluster/_k_means.pyx":52 + /* "sklearn/cluster/_k_means.pyx":50 * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( - * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< - * - * if n_samples == distances.shape[0]: - */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_center_squared_norms = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_pybuffernd_center_squared_norms.diminfo[0].strides = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_center_squared_norms.diminfo[0].shape = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.shape[0]; - } - } - __pyx_t_6 = 0; - __pyx_v_center_squared_norms = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "sklearn/cluster/_k_means.pyx":54 - * n_clusters, dtype=np.float64) * * if n_samples == distances.shape[0]: # <<<<<<<<<<<<<< * store_distances = 1 * */ - __pyx_t_7 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); - if (__pyx_t_7) { + __pyx_t_1 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); + if (__pyx_t_1) { - /* "sklearn/cluster/_k_means.pyx":55 + /* "sklearn/cluster/_k_means.pyx":51 * * if n_samples == distances.shape[0]: * store_distances = 1 # <<<<<<<<<<<<<< * - * for center_idx in range(n_clusters): + * sum, abs = np.sum, np.abs */ __pyx_v_store_distances = 1; goto __pyx_L3; } __pyx_L3:; - /* "sklearn/cluster/_k_means.pyx":57 + /* "sklearn/cluster/_k_means.pyx":53 * store_distances = 1 * - * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< - * center_squared_norms[center_idx] = ddot( - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) - */ - __pyx_t_8 = __pyx_v_n_clusters; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_center_idx = __pyx_t_9; - - /* "sklearn/cluster/_k_means.pyx":59 - * for center_idx in range(n_clusters): - * center_squared_norms[center_idx] = ddot( - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< - * + * sum, abs = np.sum, np.abs # <<<<<<<<<<<<<< * for sample_idx in range(n_samples): + * min_dist = -1 */ - __pyx_t_10 = __pyx_v_center_idx; - __pyx_t_11 = 0; - __pyx_t_12 = __pyx_v_center_idx; - __pyx_t_13 = 0; - - /* "sklearn/cluster/_k_means.pyx":58 - * - * for center_idx in range(n_clusters): - * center_squared_norms[center_idx] = ddot( # <<<<<<<<<<<<<< - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) - * - */ - __pyx_t_14 = __pyx_v_center_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides) = cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_11, __pyx_pybuffernd_centers.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_centers.diminfo[1].strides))), 1); - } + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sum); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_abs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_sum = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_v_abs = __pyx_t_4; + __pyx_t_4 = 0; - /* "sklearn/cluster/_k_means.pyx":61 - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + /* "sklearn/cluster/_k_means.pyx":54 * + * sum, abs = np.sum, np.abs * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< * min_dist = -1 * for center_idx in range(n_clusters): */ - __pyx_t_8 = __pyx_v_n_samples; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_sample_idx = __pyx_t_9; + __pyx_t_5 = __pyx_v_n_samples; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_sample_idx = __pyx_t_6; - /* "sklearn/cluster/_k_means.pyx":62 - * + /* "sklearn/cluster/_k_means.pyx":55 + * sum, abs = np.sum, np.abs * for sample_idx in range(n_samples): * min_dist = -1 # <<<<<<<<<<<<<< * for center_idx in range(n_clusters): - * dist = 0.0 + * dist = sum(abs(centers[center_idx] - X[sample_idx])) */ __pyx_v_min_dist = -1.0; - /* "sklearn/cluster/_k_means.pyx":63 + /* "sklearn/cluster/_k_means.pyx":56 * for sample_idx in range(n_samples): * min_dist = -1 * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< - * dist = 0.0 - * # hardcoded: minimize euclidean distance to cluster center: + * dist = sum(abs(centers[center_idx] - X[sample_idx])) + * if min_dist == -1 or dist < min_dist: */ - __pyx_t_15 = __pyx_v_n_clusters; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { - __pyx_v_center_idx = __pyx_t_16; + __pyx_t_7 = __pyx_v_n_clusters; + for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { + __pyx_v_center_idx = __pyx_t_8; - /* "sklearn/cluster/_k_means.pyx":64 + /* "sklearn/cluster/_k_means.pyx":57 * min_dist = -1 * for center_idx in range(n_clusters): - * dist = 0.0 # <<<<<<<<<<<<<< - * # hardcoded: minimize euclidean distance to cluster center: - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * dist = sum(abs(centers[center_idx] - X[sample_idx])) # <<<<<<<<<<<<<< + * if min_dist == -1 or dist < min_dist: + * min_dist = dist */ - __pyx_v_dist = 0.0; + __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_center_idx, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_X), __pyx_v_sample_idx, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyNumber_Subtract(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_v_abs, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_v_sum, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_9 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_dist = __pyx_t_9; - /* "sklearn/cluster/_k_means.pyx":67 - * # hardcoded: minimize euclidean distance to cluster center: - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 - * dist += ddot(n_features, &X[sample_idx, 0], 1, # <<<<<<<<<<<<<< - * ¢ers[center_idx, 0], 1) - * dist *= -2 + /* "sklearn/cluster/_k_means.pyx":58 + * for center_idx in range(n_clusters): + * dist = sum(abs(centers[center_idx] - X[sample_idx])) + * if min_dist == -1 or dist < min_dist: # <<<<<<<<<<<<<< + * min_dist = dist + * labels[sample_idx] = center_idx */ - __pyx_t_17 = __pyx_v_sample_idx; - __pyx_t_18 = 0; + __pyx_t_1 = ((__pyx_v_min_dist == -1.0) != 0); + if (!__pyx_t_1) { + __pyx_t_10 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); + __pyx_t_11 = __pyx_t_10; + } else { + __pyx_t_11 = __pyx_t_1; + } + if (__pyx_t_11) { - /* "sklearn/cluster/_k_means.pyx":68 - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 - * dist += ddot(n_features, &X[sample_idx, 0], 1, - * ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< - * dist *= -2 - * dist += center_squared_norms[center_idx] - */ - __pyx_t_19 = __pyx_v_center_idx; - __pyx_t_20 = 0; - __pyx_v_dist = (__pyx_v_dist + cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_X.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_X.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_centers.diminfo[1].strides))), 1)); - - /* "sklearn/cluster/_k_means.pyx":69 - * dist += ddot(n_features, &X[sample_idx, 0], 1, - * ¢ers[center_idx, 0], 1) - * dist *= -2 # <<<<<<<<<<<<<< - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] - */ - __pyx_v_dist = (__pyx_v_dist * -2.0); - - /* "sklearn/cluster/_k_means.pyx":70 - * ¢ers[center_idx, 0], 1) - * dist *= -2 - * dist += center_squared_norms[center_idx] # <<<<<<<<<<<<<< - * dist += x_squared_norms[sample_idx] - * if min_dist == -1 or dist < min_dist: - */ - __pyx_t_21 = __pyx_v_center_idx; - __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides))); - - /* "sklearn/cluster/_k_means.pyx":71 - * dist *= -2 - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] # <<<<<<<<<<<<<< - * if min_dist == -1 or dist < min_dist: - * min_dist = dist - */ - __pyx_t_22 = __pyx_v_sample_idx; - __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_x_squared_norms.diminfo[0].strides))); - - /* "sklearn/cluster/_k_means.pyx":72 - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] - * if min_dist == -1 or dist < min_dist: # <<<<<<<<<<<<<< - * min_dist = dist - * labels[sample_idx] = center_idx - */ - __pyx_t_7 = ((__pyx_v_min_dist == -1.0) != 0); - if (!__pyx_t_7) { - __pyx_t_23 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); - __pyx_t_24 = __pyx_t_23; - } else { - __pyx_t_24 = __pyx_t_7; - } - if (__pyx_t_24) { - - /* "sklearn/cluster/_k_means.pyx":73 - * dist += x_squared_norms[sample_idx] - * if min_dist == -1 or dist < min_dist: - * min_dist = dist # <<<<<<<<<<<<<< - * labels[sample_idx] = center_idx - * + /* "sklearn/cluster/_k_means.pyx":59 + * dist = sum(abs(centers[center_idx] - X[sample_idx])) + * if min_dist == -1 or dist < min_dist: + * min_dist = dist # <<<<<<<<<<<<<< + * labels[sample_idx] = center_idx + * */ __pyx_v_min_dist = __pyx_v_dist; - /* "sklearn/cluster/_k_means.pyx":74 + /* "sklearn/cluster/_k_means.pyx":60 * if min_dist == -1 or dist < min_dist: * min_dist = dist * labels[sample_idx] = center_idx # <<<<<<<<<<<<<< * * if store_distances: */ - __pyx_t_25 = __pyx_v_sample_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; - goto __pyx_L10; + __pyx_t_12 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; + goto __pyx_L8; } - __pyx_L10:; + __pyx_L8:; } - /* "sklearn/cluster/_k_means.pyx":76 + /* "sklearn/cluster/_k_means.pyx":62 * labels[sample_idx] = center_idx * * if store_distances: # <<<<<<<<<<<<<< * distances[sample_idx] = min_dist * inertia += min_dist */ - __pyx_t_24 = (__pyx_v_store_distances != 0); - if (__pyx_t_24) { + __pyx_t_11 = (__pyx_v_store_distances != 0); + if (__pyx_t_11) { - /* "sklearn/cluster/_k_means.pyx":77 + /* "sklearn/cluster/_k_means.pyx":63 * * if store_distances: * distances[sample_idx] = min_dist # <<<<<<<<<<<<<< * inertia += min_dist * */ - __pyx_t_15 = __pyx_v_sample_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_min_dist; - goto __pyx_L11; + __pyx_t_7 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_7, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_min_dist; + goto __pyx_L9; } - __pyx_L11:; + __pyx_L9:; - /* "sklearn/cluster/_k_means.pyx":78 + /* "sklearn/cluster/_k_means.pyx":64 * if store_distances: * distances[sample_idx] = min_dist * inertia += min_dist # <<<<<<<<<<<<<< @@ -1933,7 +1831,7 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_v_inertia = (__pyx_v_inertia + __pyx_v_min_dist); } - /* "sklearn/cluster/_k_means.pyx":80 + /* "sklearn/cluster/_k_means.pyx":66 * inertia += min_dist * * return inertia # <<<<<<<<<<<<<< @@ -1943,46 +1841,47 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_r = __pyx_v_inertia; goto __pyx_L0; - __pyx_r = 0; - goto __pyx_L0; + /* "sklearn/cluster/_k_means.pyx":32 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_array_L1(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] labels, + */ + + /* 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_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_array_L1", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_center_squared_norms); + __Pyx_XDECREF(__pyx_v_sum); + __Pyx_XDECREF(__pyx_v_abs); __Pyx_TraceReturn(Py_None); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_7cluster_8_k_means__assign_labels_array[] = "Compute label assignment and inertia for a dense array\n\n Return the inertia (sum of squared distances to the centers).\n "; -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means__assign_labels_array_L1[] = "Compute label assignment and inertia for a dense array using the L1 norm\n\n Return the inertia (sum of squared distances to the centers).\n "; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_X = 0; - PyArrayObject *__pyx_v_x_squared_norms = 0; PyArrayObject *__pyx_v_centers = 0; PyArrayObject *__pyx_v_labels = 0; PyArrayObject *__pyx_v_distances = 0; @@ -1991,15 +1890,14 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyOb int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_assign_labels_array (wrapper)", 0); + __Pyx_RefNannySetupContext("_assign_labels_array_L1 (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__x_squared_norms,&__pyx_n_s__centers,&__pyx_n_s__labels,&__pyx_n_s__distances,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_centers,&__pyx_n_s_labels,&__pyx_n_s_distances,0}; + PyObject* values[4] = {0,0,0,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 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); @@ -2010,61 +1908,55 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyOb 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--; + 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__x_squared_norms)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centers)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_array_L1", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__centers)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_array_L1", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__labels)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__distances)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_array_L1", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_array") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_array_L1") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); } __pyx_v_X = ((PyArrayObject *)values[0]); - __pyx_v_x_squared_norms = ((PyArrayObject *)values[1]); - __pyx_v_centers = ((PyArrayObject *)values[2]); - __pyx_v_labels = ((PyArrayObject *)values[3]); - __pyx_v_distances = ((PyArrayObject *)values[4]); + __pyx_v_centers = ((PyArrayObject *)values[1]); + __pyx_v_labels = ((PyArrayObject *)values[2]); + __pyx_v_distances = ((PyArrayObject *)values[3]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_array_L1", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array_L1", __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 = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array_L1(__pyx_self, __pyx_v_X, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2073,15 +1965,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array(PyOb return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":32 - * @cython.wraparound(False) - * @cython.cdivision(True) - * cpdef DOUBLE _assign_labels_array(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=1] x_squared_norms, - * np.ndarray[DOUBLE, ndim=2] centers, - */ - -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array_L1(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { __Pyx_LocalBuf_ND __pyx_pybuffernd_X; __Pyx_Buffer __pyx_pybuffer_X; __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; @@ -2090,8 +1974,6 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO __Pyx_Buffer __pyx_pybuffer_distances; __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; __Pyx_Buffer __pyx_pybuffer_labels; - __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; - __Pyx_Buffer __pyx_pybuffer_x_squared_norms; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2099,16 +1981,12 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_TraceDeclarations - __Pyx_RefNannySetupContext("_assign_labels_array", 0); - __Pyx_TraceCall("_assign_labels_array", __pyx_f[0], 32); + __Pyx_RefNannySetupContext("_assign_labels_array_L1", 0); + __Pyx_TraceCall("_assign_labels_array_L1", __pyx_f[0], 32); __pyx_pybuffer_X.pybuffer.buf = NULL; __pyx_pybuffer_X.refcount = 0; __pyx_pybuffernd_X.data = NULL; __pyx_pybuffernd_X.rcbuffer = &__pyx_pybuffer_X; - __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_x_squared_norms.refcount = 0; - __pyx_pybuffernd_x_squared_norms.data = NULL; - __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; __pyx_pybuffer_centers.pybuffer.buf = NULL; __pyx_pybuffer_centers.refcount = 0; __pyx_pybuffernd_centers.data = NULL; @@ -2126,11 +2004,6 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -2147,14 +2020,13 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array(__pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array_L1(__pyx_v_X, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; @@ -2163,9 +2035,8 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array_L1", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; @@ -2173,7 +2044,6 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r); @@ -2181,46 +2051,43 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means__assign_labels_array(CYTHO return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":86 +/* "sklearn/cluster/_k_means.pyx":72 * @cython.wraparound(False) * @cython.cdivision(True) - * cpdef DOUBLE _assign_labels_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=2] centers, - * np.ndarray[INT, ndim=1] labels, + * cpdef DOUBLE _assign_labels_csr_L1(X, np.ndarray[DOUBLE, ndim=2] centers, # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] labels, + * np.ndarray[DOUBLE, ndim=1] distances): */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr(PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr_L1(PyObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { PyArrayObject *__pyx_v_X_data = 0; PyArrayObject *__pyx_v_X_indices = 0; PyArrayObject *__pyx_v_X_indptr = 0; unsigned int __pyx_v_n_clusters; - unsigned int __pyx_v_n_features; + CYTHON_UNUSED unsigned int __pyx_v_n_features; unsigned int __pyx_v_n_samples; - unsigned int __pyx_v_store_distances; unsigned int __pyx_v_sample_idx; unsigned int __pyx_v_center_idx; + unsigned int __pyx_v_store_distances; unsigned int __pyx_v_k; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_inertia; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_min_dist; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_dist; - PyArrayObject *__pyx_v_center_squared_norms = 0; + CYTHON_UNUSED PyObject *__pyx_v_sum = NULL; + PyObject *__pyx_v_abs = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_X_data; __Pyx_Buffer __pyx_pybuffer_X_data; __Pyx_LocalBuf_ND __pyx_pybuffernd_X_indices; __Pyx_Buffer __pyx_pybuffer_X_indices; __Pyx_LocalBuf_ND __pyx_pybuffernd_X_indptr; __Pyx_Buffer __pyx_pybuffer_X_indptr; - __Pyx_LocalBuf_ND __pyx_pybuffernd_center_squared_norms; - __Pyx_Buffer __pyx_pybuffer_center_squared_norms; __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; __Pyx_Buffer __pyx_pybuffer_centers; __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; __Pyx_Buffer __pyx_pybuffer_distances; __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; __Pyx_Buffer __pyx_pybuffer_labels; - __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; - __Pyx_Buffer __pyx_pybuffer_x_squared_norms; __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2229,38 +2096,28 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ PyArrayObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; unsigned int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; + int __pyx_t_7; PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyArrayObject *__pyx_t_10 = NULL; - int __pyx_t_11; - unsigned int __pyx_t_12; - unsigned int __pyx_t_13; - long __pyx_t_14; + unsigned int __pyx_t_9; + unsigned int __pyx_t_10; + unsigned int __pyx_t_11; + long __pyx_t_12; + __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_13; + unsigned int __pyx_t_14; unsigned int __pyx_t_15; - long __pyx_t_16; + unsigned int __pyx_t_16; unsigned int __pyx_t_17; - unsigned int __pyx_t_18; + __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_18; unsigned int __pyx_t_19; - long __pyx_t_20; - __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_21; - unsigned int __pyx_t_22; - unsigned int __pyx_t_23; - unsigned int __pyx_t_24; - unsigned int __pyx_t_25; - __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_26; - unsigned int __pyx_t_27; - unsigned int __pyx_t_28; - int __pyx_t_29; - int __pyx_t_30; - unsigned int __pyx_t_31; - unsigned int __pyx_t_32; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_t_20; + int __pyx_t_21; + int __pyx_t_22; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_TraceDeclarations - __Pyx_RefNannySetupContext("_assign_labels_csr", 0); - __Pyx_TraceCall("_assign_labels_csr", __pyx_f[0], 86); + __Pyx_RefNannySetupContext("_assign_labels_csr_L1", 0); + __Pyx_TraceCall("_assign_labels_csr_L1", __pyx_f[0], 72); __pyx_pybuffer_X_data.pybuffer.buf = NULL; __pyx_pybuffer_X_data.refcount = 0; __pyx_pybuffernd_X_data.data = NULL; @@ -2273,14 +2130,6 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_pybuffer_X_indptr.refcount = 0; __pyx_pybuffernd_X_indptr.data = NULL; __pyx_pybuffernd_X_indptr.rcbuffer = &__pyx_pybuffer_X_indptr; - __pyx_pybuffer_center_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_center_squared_norms.refcount = 0; - __pyx_pybuffernd_center_squared_norms.data = NULL; - __pyx_pybuffernd_center_squared_norms.rcbuffer = &__pyx_pybuffer_center_squared_norms; - __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_x_squared_norms.refcount = 0; - __pyx_pybuffernd_x_squared_norms.data = NULL; - __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; __pyx_pybuffer_centers.pybuffer.buf = NULL; __pyx_pybuffer_centers.refcount = 0; __pyx_pybuffernd_centers.data = NULL; @@ -2295,41 +2144,36 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; - /* "sklearn/cluster/_k_means.pyx":95 + /* "sklearn/cluster/_k_means.pyx":80 * """ * cdef: * np.ndarray[DOUBLE, ndim=1] X_data = X.data # <<<<<<<<<<<<<< * np.ndarray[INT, ndim=1] X_indices = X.indices * np.ndarray[INT, ndim=1] X_indptr = X.indptr */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_data); 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); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_data.diminfo[0].strides = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_data.diminfo[0].shape = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.shape[0]; } } @@ -2337,22 +2181,22 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_v_X_data = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":96 + /* "sklearn/cluster/_k_means.pyx":81 * cdef: * np.ndarray[DOUBLE, ndim=1] X_data = X.data * np.ndarray[INT, ndim=1] X_indices = X.indices # <<<<<<<<<<<<<< * np.ndarray[INT, ndim=1] X_indptr = X.indptr * unsigned int n_clusters = centers.shape[0] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_indices.diminfo[0].strides = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indices.diminfo[0].shape = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.shape[0]; } } @@ -2360,22 +2204,22 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_v_X_indices = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":97 + /* "sklearn/cluster/_k_means.pyx":82 * np.ndarray[DOUBLE, ndim=1] X_data = X.data * np.ndarray[INT, ndim=1] X_indices = X.indices * np.ndarray[INT, ndim=1] X_indptr = X.indptr # <<<<<<<<<<<<<< * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indptr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_indptr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_indptr.diminfo[0].strides = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indptr.diminfo[0].shape = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.shape[0]; } } @@ -2383,7 +2227,7 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_v_X_indptr = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":98 + /* "sklearn/cluster/_k_means.pyx":83 * np.ndarray[INT, ndim=1] X_indices = X.indices * np.ndarray[INT, ndim=1] X_indptr = X.indptr * unsigned int n_clusters = centers.shape[0] # <<<<<<<<<<<<<< @@ -2392,42 +2236,42 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ */ __pyx_v_n_clusters = (__pyx_v_centers->dimensions[0]); - /* "sklearn/cluster/_k_means.pyx":99 + /* "sklearn/cluster/_k_means.pyx":84 * np.ndarray[INT, ndim=1] X_indptr = X.indptr * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] # <<<<<<<<<<<<<< * unsigned int n_samples = X.shape[0] - * unsigned int store_distances = 0 + * unsigned int sample_idx, center_idx */ __pyx_v_n_features = (__pyx_v_centers->dimensions[1]); - /* "sklearn/cluster/_k_means.pyx":100 + /* "sklearn/cluster/_k_means.pyx":85 * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] * unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< + * unsigned int sample_idx, center_idx * unsigned int store_distances = 0 - * unsigned int sample_idx, center_idx, feature_idx */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_5); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_5); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_n_samples = __pyx_t_6; - /* "sklearn/cluster/_k_means.pyx":101 - * unsigned int n_features = centers.shape[1] + /* "sklearn/cluster/_k_means.pyx":87 * unsigned int n_samples = X.shape[0] + * unsigned int sample_idx, center_idx * unsigned int store_distances = 0 # <<<<<<<<<<<<<< - * unsigned int sample_idx, center_idx, feature_idx * unsigned int k + * DOUBLE inertia = 0.0 */ __pyx_v_store_distances = 0; - /* "sklearn/cluster/_k_means.pyx":104 - * unsigned int sample_idx, center_idx, feature_idx + /* "sklearn/cluster/_k_means.pyx":89 + * unsigned int store_distances = 0 * unsigned int k * DOUBLE inertia = 0.0 # <<<<<<<<<<<<<< * DOUBLE min_dist @@ -2435,146 +2279,63 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ */ __pyx_v_inertia = 0.0; - /* "sklearn/cluster/_k_means.pyx":107 - * DOUBLE min_dist - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< - * n_clusters, dtype=np.float64) - * - */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "sklearn/cluster/_k_means.pyx":108 - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( - * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< - * - * if n_samples == distances.shape[0]: - */ - __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_n_clusters); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - - /* "sklearn/cluster/_k_means.pyx":107 - * DOUBLE min_dist - * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< - * n_clusters, dtype=np.float64) - * - */ - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - - /* "sklearn/cluster/_k_means.pyx":108 + /* "sklearn/cluster/_k_means.pyx":93 * DOUBLE dist - * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( - * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< - * - * if n_samples == distances.shape[0]: - */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s__float64); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = ((PyArrayObject *)__pyx_t_9); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_center_squared_norms = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_pybuffernd_center_squared_norms.diminfo[0].strides = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_center_squared_norms.diminfo[0].shape = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.shape[0]; - } - } - __pyx_t_10 = 0; - __pyx_v_center_squared_norms = ((PyArrayObject *)__pyx_t_9); - __pyx_t_9 = 0; - - /* "sklearn/cluster/_k_means.pyx":110 - * n_clusters, dtype=np.float64) * * if n_samples == distances.shape[0]: # <<<<<<<<<<<<<< * store_distances = 1 * */ - __pyx_t_11 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); - if (__pyx_t_11) { + __pyx_t_7 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); + if (__pyx_t_7) { - /* "sklearn/cluster/_k_means.pyx":111 + /* "sklearn/cluster/_k_means.pyx":94 * * if n_samples == distances.shape[0]: * store_distances = 1 # <<<<<<<<<<<<<< * - * for center_idx in range(n_clusters): + * sum, abs = np.sum, np.abs */ __pyx_v_store_distances = 1; goto __pyx_L3; } __pyx_L3:; - /* "sklearn/cluster/_k_means.pyx":113 + /* "sklearn/cluster/_k_means.pyx":96 * store_distances = 1 * - * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< - * center_squared_norms[center_idx] = ddot( - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) - */ - __pyx_t_6 = __pyx_v_n_clusters; - for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_6; __pyx_t_12+=1) { - __pyx_v_center_idx = __pyx_t_12; - - /* "sklearn/cluster/_k_means.pyx":115 - * for center_idx in range(n_clusters): - * center_squared_norms[center_idx] = ddot( - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< - * + * sum, abs = np.sum, np.abs # <<<<<<<<<<<<<< * for sample_idx in range(n_samples): + * min_dist = -1 */ - __pyx_t_13 = __pyx_v_center_idx; - __pyx_t_14 = 0; - __pyx_t_15 = __pyx_v_center_idx; - __pyx_t_16 = 0; - - /* "sklearn/cluster/_k_means.pyx":114 - * - * for center_idx in range(n_clusters): - * center_squared_norms[center_idx] = ddot( # <<<<<<<<<<<<<< - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) - * - */ - __pyx_t_17 = __pyx_v_center_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides) = cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_centers.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_centers.diminfo[1].strides))), 1); - } + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_abs); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_sum = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_v_abs = __pyx_t_8; + __pyx_t_8 = 0; - /* "sklearn/cluster/_k_means.pyx":117 - * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + /* "sklearn/cluster/_k_means.pyx":97 * + * sum, abs = np.sum, np.abs * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< * min_dist = -1 * for center_idx in range(n_clusters): */ __pyx_t_6 = __pyx_v_n_samples; - for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_6; __pyx_t_12+=1) { - __pyx_v_sample_idx = __pyx_t_12; + for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_6; __pyx_t_9+=1) { + __pyx_v_sample_idx = __pyx_t_9; - /* "sklearn/cluster/_k_means.pyx":118 - * + /* "sklearn/cluster/_k_means.pyx":98 + * sum, abs = np.sum, np.abs * for sample_idx in range(n_samples): * min_dist = -1 # <<<<<<<<<<<<<< * for center_idx in range(n_clusters): @@ -2582,147 +2343,136 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ */ __pyx_v_min_dist = -1.0; - /* "sklearn/cluster/_k_means.pyx":119 + /* "sklearn/cluster/_k_means.pyx":99 * for sample_idx in range(n_samples): * min_dist = -1 * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< * dist = 0.0 - * # hardcoded: minimize euclidean distance to cluster center: + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): */ - __pyx_t_18 = __pyx_v_n_clusters; - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { - __pyx_v_center_idx = __pyx_t_19; + __pyx_t_10 = __pyx_v_n_clusters; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { + __pyx_v_center_idx = __pyx_t_11; - /* "sklearn/cluster/_k_means.pyx":120 + /* "sklearn/cluster/_k_means.pyx":100 * min_dist = -1 * for center_idx in range(n_clusters): * dist = 0.0 # <<<<<<<<<<<<<< - * # hardcoded: minimize euclidean distance to cluster center: - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + * dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) */ __pyx_v_dist = 0.0; - /* "sklearn/cluster/_k_means.pyx":123 - * # hardcoded: minimize euclidean distance to cluster center: - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + /* "sklearn/cluster/_k_means.pyx":101 + * for center_idx in range(n_clusters): + * dist = 0.0 * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): # <<<<<<<<<<<<<< - * dist += centers[center_idx, X_indices[k]] * X_data[k] - * dist *= -2 - */ - __pyx_t_20 = (__pyx_v_sample_idx + 1); - __pyx_t_21 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); - __pyx_t_22 = __pyx_v_sample_idx; - for (__pyx_t_23 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); __pyx_t_23 < __pyx_t_21; __pyx_t_23+=1) { - __pyx_v_k = __pyx_t_23; - - /* "sklearn/cluster/_k_means.pyx":124 - * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 - * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): - * dist += centers[center_idx, X_indices[k]] * X_data[k] # <<<<<<<<<<<<<< - * dist *= -2 - * dist += center_squared_norms[center_idx] - */ - __pyx_t_24 = __pyx_v_k; - __pyx_t_25 = __pyx_v_center_idx; - __pyx_t_26 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_X_indices.diminfo[0].strides)); - __pyx_t_27 = __pyx_v_k; - __pyx_v_dist = (__pyx_v_dist + ((*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_centers.diminfo[1].strides)) * (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_X_data.diminfo[0].strides)))); - } - - /* "sklearn/cluster/_k_means.pyx":125 - * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): - * dist += centers[center_idx, X_indices[k]] * X_data[k] - * dist *= -2 # <<<<<<<<<<<<<< - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] - */ - __pyx_v_dist = (__pyx_v_dist * -2.0); - - /* "sklearn/cluster/_k_means.pyx":126 - * dist += centers[center_idx, X_indices[k]] * X_data[k] - * dist *= -2 - * dist += center_squared_norms[center_idx] # <<<<<<<<<<<<<< - * dist += x_squared_norms[sample_idx] + * dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) * if min_dist == -1 or dist < min_dist: */ - __pyx_t_23 = __pyx_v_center_idx; - __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides))); + __pyx_t_12 = (__pyx_v_sample_idx + 1); + __pyx_t_13 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); + __pyx_t_14 = __pyx_v_sample_idx; + for (__pyx_t_15 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); __pyx_t_15 < __pyx_t_13; __pyx_t_15+=1) { + __pyx_v_k = __pyx_t_15; - /* "sklearn/cluster/_k_means.pyx":127 - * dist *= -2 - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] # <<<<<<<<<<<<<< + /* "sklearn/cluster/_k_means.pyx":102 + * dist = 0.0 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + * dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) # <<<<<<<<<<<<<< * if min_dist == -1 or dist < min_dist: * min_dist = dist */ - __pyx_t_28 = __pyx_v_sample_idx; - __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_x_squared_norms.diminfo[0].strides))); + __pyx_t_8 = PyFloat_FromDouble(__pyx_v_dist); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_16 = __pyx_v_k; + __pyx_t_17 = __pyx_v_center_idx; + __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_X_indices.diminfo[0].strides)); + __pyx_t_19 = __pyx_v_k; + __pyx_t_1 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_centers.diminfo[1].strides)) - (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_X_data.diminfo[0].strides)))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_v_abs, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_20 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_20 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_dist = __pyx_t_20; + } - /* "sklearn/cluster/_k_means.pyx":128 - * dist += center_squared_norms[center_idx] - * dist += x_squared_norms[sample_idx] + /* "sklearn/cluster/_k_means.pyx":103 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + * dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) * if min_dist == -1 or dist < min_dist: # <<<<<<<<<<<<<< * min_dist = dist * labels[sample_idx] = center_idx */ - __pyx_t_11 = ((__pyx_v_min_dist == -1.0) != 0); - if (!__pyx_t_11) { - __pyx_t_29 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); - __pyx_t_30 = __pyx_t_29; + __pyx_t_7 = ((__pyx_v_min_dist == -1.0) != 0); + if (!__pyx_t_7) { + __pyx_t_21 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); + __pyx_t_22 = __pyx_t_21; } else { - __pyx_t_30 = __pyx_t_11; + __pyx_t_22 = __pyx_t_7; } - if (__pyx_t_30) { + if (__pyx_t_22) { - /* "sklearn/cluster/_k_means.pyx":129 - * dist += x_squared_norms[sample_idx] + /* "sklearn/cluster/_k_means.pyx":104 + * dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) * if min_dist == -1 or dist < min_dist: * min_dist = dist # <<<<<<<<<<<<<< * labels[sample_idx] = center_idx - * if store_distances: + * */ __pyx_v_min_dist = __pyx_v_dist; - /* "sklearn/cluster/_k_means.pyx":130 + /* "sklearn/cluster/_k_means.pyx":105 * if min_dist == -1 or dist < min_dist: * min_dist = dist * labels[sample_idx] = center_idx # <<<<<<<<<<<<<< - * if store_distances: - * distances[sample_idx] = dist + * + * if store_distances: */ - __pyx_t_31 = __pyx_v_sample_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; + __pyx_t_15 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; + goto __pyx_L10; + } + __pyx_L10:; + } - /* "sklearn/cluster/_k_means.pyx":131 - * min_dist = dist + /* "sklearn/cluster/_k_means.pyx":107 * labels[sample_idx] = center_idx - * if store_distances: # <<<<<<<<<<<<<< - * distances[sample_idx] = dist + * + * if store_distances: # <<<<<<<<<<<<<< + * distances[sample_idx] = min_dist * inertia += min_dist */ - __pyx_t_30 = (__pyx_v_store_distances != 0); - if (__pyx_t_30) { + __pyx_t_22 = (__pyx_v_store_distances != 0); + if (__pyx_t_22) { - /* "sklearn/cluster/_k_means.pyx":132 - * labels[sample_idx] = center_idx - * if store_distances: - * distances[sample_idx] = dist # <<<<<<<<<<<<<< + /* "sklearn/cluster/_k_means.pyx":108 + * + * if store_distances: + * distances[sample_idx] = min_dist # <<<<<<<<<<<<<< * inertia += min_dist * */ - __pyx_t_32 = __pyx_v_sample_idx; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_dist; - goto __pyx_L13; - } - __pyx_L13:; - goto __pyx_L12; - } - __pyx_L12:; + __pyx_t_10 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_min_dist; + goto __pyx_L11; } + __pyx_L11:; - /* "sklearn/cluster/_k_means.pyx":133 - * if store_distances: - * distances[sample_idx] = dist + /* "sklearn/cluster/_k_means.pyx":109 + * if store_distances: + * distances[sample_idx] = min_dist * inertia += min_dist # <<<<<<<<<<<<<< * * return inertia @@ -2730,7 +2480,7 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_v_inertia = (__pyx_v_inertia + __pyx_v_min_dist); } - /* "sklearn/cluster/_k_means.pyx":135 + /* "sklearn/cluster/_k_means.pyx":111 * inertia += min_dist * * return inertia # <<<<<<<<<<<<<< @@ -2740,53 +2490,54 @@ static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_ __pyx_r = __pyx_v_inertia; goto __pyx_L0; - __pyx_r = 0; - goto __pyx_L0; + /* "sklearn/cluster/_k_means.pyx":72 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_csr_L1(X, np.ndarray[DOUBLE, ndim=2] centers, # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] labels, + * np.ndarray[DOUBLE, ndim=1] distances): + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_csr_L1", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_X_data); __Pyx_XDECREF((PyObject *)__pyx_v_X_indices); __Pyx_XDECREF((PyObject *)__pyx_v_X_indptr); - __Pyx_XDECREF((PyObject *)__pyx_v_center_squared_norms); + __Pyx_XDECREF(__pyx_v_sum); + __Pyx_XDECREF(__pyx_v_abs); __Pyx_TraceReturn(Py_None); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_7cluster_8_k_means_2_assign_labels_csr[] = "Compute label assignment and inertia for a CSR input\n\n Return the inertia (sum of squared distances to the centers).\n "; -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_2_assign_labels_csr_L1[] = "Compute label assignment and inertia for a dense array using the L1 norm\n\n Return the inertia (sum of squared distances to the centers).\n "; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr_L1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_X = 0; - PyArrayObject *__pyx_v_x_squared_norms = 0; PyArrayObject *__pyx_v_centers = 0; PyArrayObject *__pyx_v_labels = 0; PyArrayObject *__pyx_v_distances = 0; @@ -2795,15 +2546,14 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObje int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_assign_labels_csr (wrapper)", 0); + __Pyx_RefNannySetupContext("_assign_labels_csr_L1 (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__x_squared_norms,&__pyx_n_s__centers,&__pyx_n_s__labels,&__pyx_n_s__distances,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_centers,&__pyx_n_s_labels,&__pyx_n_s_distances,0}; + PyObject* values[4] = {0,0,0,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 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); @@ -2814,60 +2564,54 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObje 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--; + 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__x_squared_norms)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centers)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr_L1", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__centers)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr_L1", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__labels)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__distances)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr_L1", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_csr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_csr_L1") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); } __pyx_v_X = values[0]; - __pyx_v_x_squared_norms = ((PyArrayObject *)values[1]); - __pyx_v_centers = ((PyArrayObject *)values[2]); - __pyx_v_labels = ((PyArrayObject *)values[3]); - __pyx_v_distances = ((PyArrayObject *)values[4]); + __pyx_v_centers = ((PyArrayObject *)values[1]); + __pyx_v_labels = ((PyArrayObject *)values[2]); + __pyx_v_distances = ((PyArrayObject *)values[3]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr_L1", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr_L1", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr_L1(__pyx_self, __pyx_v_X, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2876,23 +2620,13 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr(PyObje return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":86 - * @cython.wraparound(False) - * @cython.cdivision(True) - * cpdef DOUBLE _assign_labels_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=2] centers, - * np.ndarray[INT, ndim=1] labels, - */ - -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr_L1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; __Pyx_Buffer __pyx_pybuffer_centers; __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; __Pyx_Buffer __pyx_pybuffer_distances; __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; __Pyx_Buffer __pyx_pybuffer_labels; - __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; - __Pyx_Buffer __pyx_pybuffer_x_squared_norms; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2900,12 +2634,8 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_TraceDeclarations - __Pyx_RefNannySetupContext("_assign_labels_csr", 0); - __Pyx_TraceCall("_assign_labels_csr", __pyx_f[0], 86); - __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; - __pyx_pybuffer_x_squared_norms.refcount = 0; - __pyx_pybuffernd_x_squared_norms.data = NULL; - __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; + __Pyx_RefNannySetupContext("_assign_labels_csr_L1", 0); + __Pyx_TraceCall("_assign_labels_csr_L1", __pyx_f[0], 72); __pyx_pybuffer_centers.pybuffer.buf = NULL; __pyx_pybuffer_centers.refcount = 0; __pyx_pybuffernd_centers.data = NULL; @@ -2920,33 +2650,27 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr(__pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr_L1(__pyx_v_X, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; @@ -2954,16 +2678,14 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr_L1", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r); @@ -2971,79 +2693,1598 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_2_assign_labels_csr(CYTHON return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr[] = "Incremental update of the centers for sparse MiniBatchKMeans.\n\n Parameters\n ----------\n\n X: CSR matrix, dtype float64\n The complete (pre allocated) training set as a CSR matrix.\n\n centers: array, shape (n_clusters, n_features)\n The cluster centers\n\n counts: array, shape (n_clusters,)\n The vector in which we keep track of the numbers of elements in a\n cluster\n\n Returns\n -------\n inertia: float\n The inertia of the batch prior to centers update, i.e. the sum\n distances to the closest center for each sample. This is the objective\n function being minimized by the k-means algorithm.\n\n squared_diff: float\n The sum of squared update (squared norm of the centers position\n change). If compute_squared_diff is 0, this computation is skipped and\n 0.0 is returned instead.\n\n Both squared diff and inertia are commonly used to monitor the convergence\n of the algorithm.\n "; -static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr = {__Pyx_NAMESTR("_mini_batch_update_csr"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr)}; -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_X = 0; - CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms = 0; - PyArrayObject *__pyx_v_centers = 0; - PyArrayObject *__pyx_v_counts = 0; - PyArrayObject *__pyx_v_nearest_center = 0; - PyArrayObject *__pyx_v_old_center = 0; - int __pyx_v_compute_squared_diff; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyObject *__pyx_r = 0; +/* "sklearn/cluster/_k_means.pyx":117 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_array(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=1] x_squared_norms, + * np.ndarray[DOUBLE, ndim=2] centers, + */ + +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array(PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { + unsigned int __pyx_v_n_clusters; + unsigned int __pyx_v_n_features; + unsigned int __pyx_v_n_samples; + unsigned int __pyx_v_sample_idx; + unsigned int __pyx_v_center_idx; + unsigned int __pyx_v_store_distances; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_inertia; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_min_dist; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_dist; + PyArrayObject *__pyx_v_center_squared_norms = 0; + __Pyx_LocalBuf_ND __pyx_pybuffernd_X; + __Pyx_Buffer __pyx_pybuffer_X; + __Pyx_LocalBuf_ND __pyx_pybuffernd_center_squared_norms; + __Pyx_Buffer __pyx_pybuffer_center_squared_norms; + __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; + __Pyx_Buffer __pyx_pybuffer_centers; + __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; + __Pyx_Buffer __pyx_pybuffer_distances; + __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; + __Pyx_Buffer __pyx_pybuffer_labels; + __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; + __Pyx_Buffer __pyx_pybuffer_x_squared_norms; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_mini_batch_update_csr (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__x_squared_norms,&__pyx_n_s__centers,&__pyx_n_s__counts,&__pyx_n_s__nearest_center,&__pyx_n_s__old_center,&__pyx_n_s_1,0}; - PyObject* values[7] = {0,0,0,0,0,0,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 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - 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; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyArrayObject *__pyx_t_6 = NULL; + int __pyx_t_7; + unsigned int __pyx_t_8; + unsigned int __pyx_t_9; + unsigned int __pyx_t_10; + long __pyx_t_11; + unsigned int __pyx_t_12; + long __pyx_t_13; + unsigned int __pyx_t_14; + unsigned int __pyx_t_15; + unsigned int __pyx_t_16; + unsigned int __pyx_t_17; + long __pyx_t_18; + unsigned int __pyx_t_19; + long __pyx_t_20; + unsigned int __pyx_t_21; + unsigned int __pyx_t_22; + int __pyx_t_23; + int __pyx_t_24; + unsigned int __pyx_t_25; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_TraceDeclarations + __Pyx_RefNannySetupContext("_assign_labels_array", 0); + __Pyx_TraceCall("_assign_labels_array", __pyx_f[0], 117); + __pyx_pybuffer_center_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_center_squared_norms.refcount = 0; + __pyx_pybuffernd_center_squared_norms.data = NULL; + __pyx_pybuffernd_center_squared_norms.rcbuffer = &__pyx_pybuffer_center_squared_norms; + __pyx_pybuffer_X.pybuffer.buf = NULL; + __pyx_pybuffer_X.refcount = 0; + __pyx_pybuffernd_X.data = NULL; + __pyx_pybuffernd_X.rcbuffer = &__pyx_pybuffer_X; + __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_x_squared_norms.refcount = 0; + __pyx_pybuffernd_x_squared_norms.data = NULL; + __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; + __pyx_pybuffer_centers.pybuffer.buf = NULL; + __pyx_pybuffer_centers.refcount = 0; + __pyx_pybuffernd_centers.data = NULL; + __pyx_pybuffernd_centers.rcbuffer = &__pyx_pybuffer_centers; + __pyx_pybuffer_labels.pybuffer.buf = NULL; + __pyx_pybuffer_labels.refcount = 0; + __pyx_pybuffernd_labels.data = NULL; + __pyx_pybuffernd_labels.rcbuffer = &__pyx_pybuffer_labels; + __pyx_pybuffer_distances.pybuffer.buf = NULL; + __pyx_pybuffer_distances.refcount = 0; + __pyx_pybuffernd_distances.data = NULL; + __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; + + /* "sklearn/cluster/_k_means.pyx":127 + * """ + * cdef: + * unsigned int n_clusters = centers.shape[0] # <<<<<<<<<<<<<< + * unsigned int n_features = centers.shape[1] + * unsigned int n_samples = X.shape[0] + */ + __pyx_v_n_clusters = (__pyx_v_centers->dimensions[0]); + + /* "sklearn/cluster/_k_means.pyx":128 + * cdef: + * unsigned int n_clusters = centers.shape[0] + * unsigned int n_features = centers.shape[1] # <<<<<<<<<<<<<< + * unsigned int n_samples = X.shape[0] + * unsigned int sample_idx, center_idx, feature_idx + */ + __pyx_v_n_features = (__pyx_v_centers->dimensions[1]); + + /* "sklearn/cluster/_k_means.pyx":129 + * unsigned int n_clusters = centers.shape[0] + * unsigned int n_features = centers.shape[1] + * unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< + * unsigned int sample_idx, center_idx, feature_idx + * unsigned int store_distances = 0 + */ + __pyx_v_n_samples = (__pyx_v_X->dimensions[0]); + + /* "sklearn/cluster/_k_means.pyx":131 + * unsigned int n_samples = X.shape[0] + * unsigned int sample_idx, center_idx, feature_idx + * unsigned int store_distances = 0 # <<<<<<<<<<<<<< + * unsigned int k + * DOUBLE inertia = 0.0 + */ + __pyx_v_store_distances = 0; + + /* "sklearn/cluster/_k_means.pyx":133 + * unsigned int store_distances = 0 + * unsigned int k + * DOUBLE inertia = 0.0 # <<<<<<<<<<<<<< + * DOUBLE min_dist + * DOUBLE dist + */ + __pyx_v_inertia = 0.0; + + /* "sklearn/cluster/_k_means.pyx":136 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __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 = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "sklearn/cluster/_k_means.pyx":137 + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( + * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< + * + * if n_samples == distances.shape[0]: + */ + __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_clusters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "sklearn/cluster/_k_means.pyx":136 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "sklearn/cluster/_k_means.pyx":137 + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( + * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< + * + * if n_samples == distances.shape[0]: + */ + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "sklearn/cluster/_k_means.pyx":136 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_5 = PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __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; + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + __pyx_v_center_squared_norms = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_center_squared_norms.diminfo[0].strides = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_center_squared_norms.diminfo[0].shape = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_6 = 0; + __pyx_v_center_squared_norms = ((PyArrayObject *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "sklearn/cluster/_k_means.pyx":139 + * n_clusters, dtype=np.float64) + * + * if n_samples == distances.shape[0]: # <<<<<<<<<<<<<< + * store_distances = 1 + * + */ + __pyx_t_7 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); + if (__pyx_t_7) { + + /* "sklearn/cluster/_k_means.pyx":140 + * + * if n_samples == distances.shape[0]: + * store_distances = 1 # <<<<<<<<<<<<<< + * + * for center_idx in range(n_clusters): + */ + __pyx_v_store_distances = 1; + goto __pyx_L3; + } + __pyx_L3:; + + /* "sklearn/cluster/_k_means.pyx":142 + * store_distances = 1 + * + * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< + * center_squared_norms[center_idx] = ddot( + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + */ + __pyx_t_8 = __pyx_v_n_clusters; + for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { + __pyx_v_center_idx = __pyx_t_9; + + /* "sklearn/cluster/_k_means.pyx":144 + * for center_idx in range(n_clusters): + * center_squared_norms[center_idx] = ddot( + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< + * + * for sample_idx in range(n_samples): + */ + __pyx_t_10 = __pyx_v_center_idx; + __pyx_t_11 = 0; + __pyx_t_12 = __pyx_v_center_idx; + __pyx_t_13 = 0; + + /* "sklearn/cluster/_k_means.pyx":143 + * + * for center_idx in range(n_clusters): + * center_squared_norms[center_idx] = ddot( # <<<<<<<<<<<<<< + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + * + */ + __pyx_t_14 = __pyx_v_center_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides) = cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_11, __pyx_pybuffernd_centers.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_centers.diminfo[1].strides))), 1); + } + + /* "sklearn/cluster/_k_means.pyx":146 + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + * + * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< + * min_dist = -1 + * for center_idx in range(n_clusters): + */ + __pyx_t_8 = __pyx_v_n_samples; + for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { + __pyx_v_sample_idx = __pyx_t_9; + + /* "sklearn/cluster/_k_means.pyx":147 + * + * for sample_idx in range(n_samples): + * min_dist = -1 # <<<<<<<<<<<<<< + * for center_idx in range(n_clusters): + * dist = 0.0 + */ + __pyx_v_min_dist = -1.0; + + /* "sklearn/cluster/_k_means.pyx":148 + * for sample_idx in range(n_samples): + * min_dist = -1 + * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< + * dist = 0.0 + * # hardcoded: minimize euclidean distance to cluster center: + */ + __pyx_t_15 = __pyx_v_n_clusters; + for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { + __pyx_v_center_idx = __pyx_t_16; + + /* "sklearn/cluster/_k_means.pyx":149 + * min_dist = -1 + * for center_idx in range(n_clusters): + * dist = 0.0 # <<<<<<<<<<<<<< + * # hardcoded: minimize euclidean distance to cluster center: + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + */ + __pyx_v_dist = 0.0; + + /* "sklearn/cluster/_k_means.pyx":152 + * # hardcoded: minimize euclidean distance to cluster center: + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * dist += ddot(n_features, &X[sample_idx, 0], 1, # <<<<<<<<<<<<<< + * ¢ers[center_idx, 0], 1) + * dist *= -2 + */ + __pyx_t_17 = __pyx_v_sample_idx; + __pyx_t_18 = 0; + + /* "sklearn/cluster/_k_means.pyx":153 + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * dist += ddot(n_features, &X[sample_idx, 0], 1, + * ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< + * dist *= -2 + * dist += center_squared_norms[center_idx] + */ + __pyx_t_19 = __pyx_v_center_idx; + __pyx_t_20 = 0; + + /* "sklearn/cluster/_k_means.pyx":152 + * # hardcoded: minimize euclidean distance to cluster center: + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * dist += ddot(n_features, &X[sample_idx, 0], 1, # <<<<<<<<<<<<<< + * ¢ers[center_idx, 0], 1) + * dist *= -2 + */ + __pyx_v_dist = (__pyx_v_dist + cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_X.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_X.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_X.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_centers.diminfo[1].strides))), 1)); + + /* "sklearn/cluster/_k_means.pyx":154 + * dist += ddot(n_features, &X[sample_idx, 0], 1, + * ¢ers[center_idx, 0], 1) + * dist *= -2 # <<<<<<<<<<<<<< + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] + */ + __pyx_v_dist = (__pyx_v_dist * -2.0); + + /* "sklearn/cluster/_k_means.pyx":155 + * ¢ers[center_idx, 0], 1) + * dist *= -2 + * dist += center_squared_norms[center_idx] # <<<<<<<<<<<<<< + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: + */ + __pyx_t_21 = __pyx_v_center_idx; + __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides))); + + /* "sklearn/cluster/_k_means.pyx":156 + * dist *= -2 + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] # <<<<<<<<<<<<<< + * if min_dist == -1 or dist < min_dist: + * min_dist = dist + */ + __pyx_t_22 = __pyx_v_sample_idx; + __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_x_squared_norms.diminfo[0].strides))); + + /* "sklearn/cluster/_k_means.pyx":157 + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: # <<<<<<<<<<<<<< + * min_dist = dist + * labels[sample_idx] = center_idx + */ + __pyx_t_7 = ((__pyx_v_min_dist == -1.0) != 0); + if (!__pyx_t_7) { + __pyx_t_23 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); + __pyx_t_24 = __pyx_t_23; + } else { + __pyx_t_24 = __pyx_t_7; + } + if (__pyx_t_24) { + + /* "sklearn/cluster/_k_means.pyx":158 + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: + * min_dist = dist # <<<<<<<<<<<<<< + * labels[sample_idx] = center_idx + * + */ + __pyx_v_min_dist = __pyx_v_dist; + + /* "sklearn/cluster/_k_means.pyx":159 + * if min_dist == -1 or dist < min_dist: + * min_dist = dist + * labels[sample_idx] = center_idx # <<<<<<<<<<<<<< + * + * if store_distances: + */ + __pyx_t_25 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; + goto __pyx_L10; + } + __pyx_L10:; + } + + /* "sklearn/cluster/_k_means.pyx":161 + * labels[sample_idx] = center_idx + * + * if store_distances: # <<<<<<<<<<<<<< + * distances[sample_idx] = min_dist + * inertia += min_dist + */ + __pyx_t_24 = (__pyx_v_store_distances != 0); + if (__pyx_t_24) { + + /* "sklearn/cluster/_k_means.pyx":162 + * + * if store_distances: + * distances[sample_idx] = min_dist # <<<<<<<<<<<<<< + * inertia += min_dist + * + */ + __pyx_t_15 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_min_dist; + goto __pyx_L11; + } + __pyx_L11:; + + /* "sklearn/cluster/_k_means.pyx":163 + * if store_distances: + * distances[sample_idx] = min_dist + * inertia += min_dist # <<<<<<<<<<<<<< + * + * return inertia + */ + __pyx_v_inertia = (__pyx_v_inertia + __pyx_v_min_dist); + } + + /* "sklearn/cluster/_k_means.pyx":165 + * inertia += min_dist + * + * return inertia # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_inertia; + goto __pyx_L0; + + /* "sklearn/cluster/_k_means.pyx":117 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_array(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=1] x_squared_norms, + * np.ndarray[DOUBLE, ndim=2] centers, + */ + + /* 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_5); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_array", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); + __pyx_r = 0; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_center_squared_norms); + __Pyx_TraceReturn(Py_None); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_4_assign_labels_array[] = "Compute label assignment and inertia for a dense array\n\n Return the inertia (sum of squared distances to the centers).\n "; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_assign_labels_array(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_X = 0; + PyArrayObject *__pyx_v_x_squared_norms = 0; + PyArrayObject *__pyx_v_centers = 0; + PyArrayObject *__pyx_v_labels = 0; + PyArrayObject *__pyx_v_distances = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_assign_labels_array (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_x_squared_norms,&__pyx_n_s_centers,&__pyx_n_s_labels,&__pyx_n_s_distances,0}; + PyObject* values[5] = {0,0,0,0,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 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_x_squared_norms)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centers)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_array") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + } + __pyx_v_X = ((PyArrayObject *)values[0]); + __pyx_v_x_squared_norms = ((PyArrayObject *)values[1]); + __pyx_v_centers = ((PyArrayObject *)values[2]); + __pyx_v_labels = ((PyArrayObject *)values[3]); + __pyx_v_distances = ((PyArrayObject *)values[4]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_assign_labels_array", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array", __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 = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_4_assign_labels_array(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_assign_labels_array(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { + __Pyx_LocalBuf_ND __pyx_pybuffernd_X; + __Pyx_Buffer __pyx_pybuffer_X; + __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; + __Pyx_Buffer __pyx_pybuffer_centers; + __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; + __Pyx_Buffer __pyx_pybuffer_distances; + __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; + __Pyx_Buffer __pyx_pybuffer_labels; + __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; + __Pyx_Buffer __pyx_pybuffer_x_squared_norms; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_TraceDeclarations + __Pyx_RefNannySetupContext("_assign_labels_array", 0); + __Pyx_TraceCall("_assign_labels_array", __pyx_f[0], 117); + __pyx_pybuffer_X.pybuffer.buf = NULL; + __pyx_pybuffer_X.refcount = 0; + __pyx_pybuffernd_X.data = NULL; + __pyx_pybuffernd_X.rcbuffer = &__pyx_pybuffer_X; + __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_x_squared_norms.refcount = 0; + __pyx_pybuffernd_x_squared_norms.data = NULL; + __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; + __pyx_pybuffer_centers.pybuffer.buf = NULL; + __pyx_pybuffer_centers.refcount = 0; + __pyx_pybuffernd_centers.data = NULL; + __pyx_pybuffernd_centers.rcbuffer = &__pyx_pybuffer_centers; + __pyx_pybuffer_labels.pybuffer.buf = NULL; + __pyx_pybuffer_labels.refcount = 0; + __pyx_pybuffernd_labels.data = NULL; + __pyx_pybuffernd_labels.rcbuffer = &__pyx_pybuffer_labels; + __pyx_pybuffer_distances.pybuffer.buf = NULL; + __pyx_pybuffer_distances.refcount = 0; + __pyx_pybuffernd_distances.data = NULL; + __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_array(__pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __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); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "sklearn/cluster/_k_means.pyx":171 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] labels, + */ + +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr(PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances, CYTHON_UNUSED int __pyx_skip_dispatch) { + PyArrayObject *__pyx_v_X_data = 0; + PyArrayObject *__pyx_v_X_indices = 0; + PyArrayObject *__pyx_v_X_indptr = 0; + unsigned int __pyx_v_n_clusters; + unsigned int __pyx_v_n_features; + unsigned int __pyx_v_n_samples; + unsigned int __pyx_v_store_distances; + unsigned int __pyx_v_sample_idx; + unsigned int __pyx_v_center_idx; + unsigned int __pyx_v_k; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_inertia; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_min_dist; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_v_dist; + PyArrayObject *__pyx_v_center_squared_norms = 0; + __Pyx_LocalBuf_ND __pyx_pybuffernd_X_data; + __Pyx_Buffer __pyx_pybuffer_X_data; + __Pyx_LocalBuf_ND __pyx_pybuffernd_X_indices; + __Pyx_Buffer __pyx_pybuffer_X_indices; + __Pyx_LocalBuf_ND __pyx_pybuffernd_X_indptr; + __Pyx_Buffer __pyx_pybuffer_X_indptr; + __Pyx_LocalBuf_ND __pyx_pybuffernd_center_squared_norms; + __Pyx_Buffer __pyx_pybuffer_center_squared_norms; + __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; + __Pyx_Buffer __pyx_pybuffer_centers; + __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; + __Pyx_Buffer __pyx_pybuffer_distances; + __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; + __Pyx_Buffer __pyx_pybuffer_labels; + __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; + __Pyx_Buffer __pyx_pybuffer_x_squared_norms; + __pyx_t_7sklearn_7cluster_8_k_means_DOUBLE __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyArrayObject *__pyx_t_2 = NULL; + PyArrayObject *__pyx_t_3 = NULL; + PyArrayObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyArrayObject *__pyx_t_10 = NULL; + int __pyx_t_11; + unsigned int __pyx_t_12; + unsigned int __pyx_t_13; + long __pyx_t_14; + unsigned int __pyx_t_15; + long __pyx_t_16; + unsigned int __pyx_t_17; + unsigned int __pyx_t_18; + unsigned int __pyx_t_19; + long __pyx_t_20; + __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_21; + unsigned int __pyx_t_22; + unsigned int __pyx_t_23; + unsigned int __pyx_t_24; + unsigned int __pyx_t_25; + __pyx_t_7sklearn_7cluster_8_k_means_INT __pyx_t_26; + unsigned int __pyx_t_27; + unsigned int __pyx_t_28; + int __pyx_t_29; + int __pyx_t_30; + unsigned int __pyx_t_31; + unsigned int __pyx_t_32; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_TraceDeclarations + __Pyx_RefNannySetupContext("_assign_labels_csr", 0); + __Pyx_TraceCall("_assign_labels_csr", __pyx_f[0], 171); + __pyx_pybuffer_X_data.pybuffer.buf = NULL; + __pyx_pybuffer_X_data.refcount = 0; + __pyx_pybuffernd_X_data.data = NULL; + __pyx_pybuffernd_X_data.rcbuffer = &__pyx_pybuffer_X_data; + __pyx_pybuffer_X_indices.pybuffer.buf = NULL; + __pyx_pybuffer_X_indices.refcount = 0; + __pyx_pybuffernd_X_indices.data = NULL; + __pyx_pybuffernd_X_indices.rcbuffer = &__pyx_pybuffer_X_indices; + __pyx_pybuffer_X_indptr.pybuffer.buf = NULL; + __pyx_pybuffer_X_indptr.refcount = 0; + __pyx_pybuffernd_X_indptr.data = NULL; + __pyx_pybuffernd_X_indptr.rcbuffer = &__pyx_pybuffer_X_indptr; + __pyx_pybuffer_center_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_center_squared_norms.refcount = 0; + __pyx_pybuffernd_center_squared_norms.data = NULL; + __pyx_pybuffernd_center_squared_norms.rcbuffer = &__pyx_pybuffer_center_squared_norms; + __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_x_squared_norms.refcount = 0; + __pyx_pybuffernd_x_squared_norms.data = NULL; + __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; + __pyx_pybuffer_centers.pybuffer.buf = NULL; + __pyx_pybuffer_centers.refcount = 0; + __pyx_pybuffernd_centers.data = NULL; + __pyx_pybuffernd_centers.rcbuffer = &__pyx_pybuffer_centers; + __pyx_pybuffer_labels.pybuffer.buf = NULL; + __pyx_pybuffer_labels.refcount = 0; + __pyx_pybuffernd_labels.data = NULL; + __pyx_pybuffernd_labels.rcbuffer = &__pyx_pybuffer_labels; + __pyx_pybuffer_distances.pybuffer.buf = NULL; + __pyx_pybuffer_distances.refcount = 0; + __pyx_pybuffernd_distances.data = NULL; + __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; + + /* "sklearn/cluster/_k_means.pyx":180 + * """ + * cdef: + * np.ndarray[DOUBLE, ndim=1] X_data = X.data # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] X_indices = X.indices + * np.ndarray[INT, ndim=1] X_indptr = X.indptr + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + __pyx_v_X_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_X_data.diminfo[0].strides = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_data.diminfo[0].shape = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_2 = 0; + __pyx_v_X_data = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "sklearn/cluster/_k_means.pyx":181 + * cdef: + * np.ndarray[DOUBLE, ndim=1] X_data = X.data + * np.ndarray[INT, ndim=1] X_indices = X.indices # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] X_indptr = X.indptr + * unsigned int n_clusters = centers.shape[0] + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + __pyx_v_X_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_X_indices.diminfo[0].strides = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indices.diminfo[0].shape = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_3 = 0; + __pyx_v_X_indices = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "sklearn/cluster/_k_means.pyx":182 + * np.ndarray[DOUBLE, ndim=1] X_data = X.data + * np.ndarray[INT, ndim=1] X_indices = X.indices + * np.ndarray[INT, ndim=1] X_indptr = X.indptr # <<<<<<<<<<<<<< + * unsigned int n_clusters = centers.shape[0] + * unsigned int n_features = centers.shape[1] + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((PyArrayObject *)__pyx_t_1); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + __pyx_v_X_indptr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_X_indptr.diminfo[0].strides = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indptr.diminfo[0].shape = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_4 = 0; + __pyx_v_X_indptr = ((PyArrayObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "sklearn/cluster/_k_means.pyx":183 + * np.ndarray[INT, ndim=1] X_indices = X.indices + * np.ndarray[INT, ndim=1] X_indptr = X.indptr + * unsigned int n_clusters = centers.shape[0] # <<<<<<<<<<<<<< + * unsigned int n_features = centers.shape[1] + * unsigned int n_samples = X.shape[0] + */ + __pyx_v_n_clusters = (__pyx_v_centers->dimensions[0]); + + /* "sklearn/cluster/_k_means.pyx":184 + * np.ndarray[INT, ndim=1] X_indptr = X.indptr + * unsigned int n_clusters = centers.shape[0] + * unsigned int n_features = centers.shape[1] # <<<<<<<<<<<<<< + * unsigned int n_samples = X.shape[0] + * unsigned int store_distances = 0 + */ + __pyx_v_n_features = (__pyx_v_centers->dimensions[1]); + + /* "sklearn/cluster/_k_means.pyx":185 + * unsigned int n_clusters = centers.shape[0] + * unsigned int n_features = centers.shape[1] + * unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< + * unsigned int store_distances = 0 + * unsigned int sample_idx, center_idx, feature_idx + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_5); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_n_samples = __pyx_t_6; + + /* "sklearn/cluster/_k_means.pyx":186 + * unsigned int n_features = centers.shape[1] + * unsigned int n_samples = X.shape[0] + * unsigned int store_distances = 0 # <<<<<<<<<<<<<< + * unsigned int sample_idx, center_idx, feature_idx + * unsigned int k + */ + __pyx_v_store_distances = 0; + + /* "sklearn/cluster/_k_means.pyx":189 + * unsigned int sample_idx, center_idx, feature_idx + * unsigned int k + * DOUBLE inertia = 0.0 # <<<<<<<<<<<<<< + * DOUBLE min_dist + * DOUBLE dist + */ + __pyx_v_inertia = 0.0; + + /* "sklearn/cluster/_k_means.pyx":192 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "sklearn/cluster/_k_means.pyx":193 + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( + * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< + * + * if n_samples == distances.shape[0]: + */ + __pyx_t_5 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_clusters); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + + /* "sklearn/cluster/_k_means.pyx":192 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + + /* "sklearn/cluster/_k_means.pyx":193 + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( + * n_clusters, dtype=np.float64) # <<<<<<<<<<<<<< + * + * if n_samples == distances.shape[0]: + */ + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "sklearn/cluster/_k_means.pyx":192 + * DOUBLE min_dist + * DOUBLE dist + * np.ndarray[DOUBLE, ndim=1] center_squared_norms = np.zeros( # <<<<<<<<<<<<<< + * n_clusters, dtype=np.float64) + * + */ + __pyx_t_9 = PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = ((PyArrayObject *)__pyx_t_9); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + __pyx_v_center_squared_norms = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_center_squared_norms.diminfo[0].strides = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_center_squared_norms.diminfo[0].shape = __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_10 = 0; + __pyx_v_center_squared_norms = ((PyArrayObject *)__pyx_t_9); + __pyx_t_9 = 0; + + /* "sklearn/cluster/_k_means.pyx":195 + * n_clusters, dtype=np.float64) + * + * if n_samples == distances.shape[0]: # <<<<<<<<<<<<<< + * store_distances = 1 + * + */ + __pyx_t_11 = ((__pyx_v_n_samples == (__pyx_v_distances->dimensions[0])) != 0); + if (__pyx_t_11) { + + /* "sklearn/cluster/_k_means.pyx":196 + * + * if n_samples == distances.shape[0]: + * store_distances = 1 # <<<<<<<<<<<<<< + * + * for center_idx in range(n_clusters): + */ + __pyx_v_store_distances = 1; + goto __pyx_L3; + } + __pyx_L3:; + + /* "sklearn/cluster/_k_means.pyx":198 + * store_distances = 1 + * + * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< + * center_squared_norms[center_idx] = ddot( + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + */ + __pyx_t_6 = __pyx_v_n_clusters; + for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_6; __pyx_t_12+=1) { + __pyx_v_center_idx = __pyx_t_12; + + /* "sklearn/cluster/_k_means.pyx":200 + * for center_idx in range(n_clusters): + * center_squared_norms[center_idx] = ddot( + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) # <<<<<<<<<<<<<< + * + * for sample_idx in range(n_samples): + */ + __pyx_t_13 = __pyx_v_center_idx; + __pyx_t_14 = 0; + __pyx_t_15 = __pyx_v_center_idx; + __pyx_t_16 = 0; + + /* "sklearn/cluster/_k_means.pyx":199 + * + * for center_idx in range(n_clusters): + * center_squared_norms[center_idx] = ddot( # <<<<<<<<<<<<<< + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + * + */ + __pyx_t_17 = __pyx_v_center_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides) = cblas_ddot(__pyx_v_n_features, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_centers.diminfo[1].strides))), 1, (&(*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_centers.diminfo[1].strides))), 1); + } + + /* "sklearn/cluster/_k_means.pyx":202 + * n_features, ¢ers[center_idx, 0], 1, ¢ers[center_idx, 0], 1) + * + * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< + * min_dist = -1 + * for center_idx in range(n_clusters): + */ + __pyx_t_6 = __pyx_v_n_samples; + for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_6; __pyx_t_12+=1) { + __pyx_v_sample_idx = __pyx_t_12; + + /* "sklearn/cluster/_k_means.pyx":203 + * + * for sample_idx in range(n_samples): + * min_dist = -1 # <<<<<<<<<<<<<< + * for center_idx in range(n_clusters): + * dist = 0.0 + */ + __pyx_v_min_dist = -1.0; + + /* "sklearn/cluster/_k_means.pyx":204 + * for sample_idx in range(n_samples): + * min_dist = -1 + * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< + * dist = 0.0 + * # hardcoded: minimize euclidean distance to cluster center: + */ + __pyx_t_18 = __pyx_v_n_clusters; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { + __pyx_v_center_idx = __pyx_t_19; + + /* "sklearn/cluster/_k_means.pyx":205 + * min_dist = -1 + * for center_idx in range(n_clusters): + * dist = 0.0 # <<<<<<<<<<<<<< + * # hardcoded: minimize euclidean distance to cluster center: + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + */ + __pyx_v_dist = 0.0; + + /* "sklearn/cluster/_k_means.pyx":208 + * # hardcoded: minimize euclidean distance to cluster center: + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): # <<<<<<<<<<<<<< + * dist += centers[center_idx, X_indices[k]] * X_data[k] + * dist *= -2 + */ + __pyx_t_20 = (__pyx_v_sample_idx + 1); + __pyx_t_21 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); + __pyx_t_22 = __pyx_v_sample_idx; + for (__pyx_t_23 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); __pyx_t_23 < __pyx_t_21; __pyx_t_23+=1) { + __pyx_v_k = __pyx_t_23; + + /* "sklearn/cluster/_k_means.pyx":209 + * # ||a - b||^2 = ||a||^2 + ||b||^2 -2 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + * dist += centers[center_idx, X_indices[k]] * X_data[k] # <<<<<<<<<<<<<< + * dist *= -2 + * dist += center_squared_norms[center_idx] + */ + __pyx_t_24 = __pyx_v_k; + __pyx_t_25 = __pyx_v_center_idx; + __pyx_t_26 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_X_indices.diminfo[0].strides)); + __pyx_t_27 = __pyx_v_k; + __pyx_v_dist = (__pyx_v_dist + ((*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_centers.diminfo[1].strides)) * (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_X_data.diminfo[0].strides)))); + } + + /* "sklearn/cluster/_k_means.pyx":210 + * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + * dist += centers[center_idx, X_indices[k]] * X_data[k] + * dist *= -2 # <<<<<<<<<<<<<< + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] + */ + __pyx_v_dist = (__pyx_v_dist * -2.0); + + /* "sklearn/cluster/_k_means.pyx":211 + * dist += centers[center_idx, X_indices[k]] * X_data[k] + * dist *= -2 + * dist += center_squared_norms[center_idx] # <<<<<<<<<<<<<< + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: + */ + __pyx_t_23 = __pyx_v_center_idx; + __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_center_squared_norms.diminfo[0].strides))); + + /* "sklearn/cluster/_k_means.pyx":212 + * dist *= -2 + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] # <<<<<<<<<<<<<< + * if min_dist == -1 or dist < min_dist: + * min_dist = dist + */ + __pyx_t_28 = __pyx_v_sample_idx; + __pyx_v_dist = (__pyx_v_dist + (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_x_squared_norms.diminfo[0].strides))); + + /* "sklearn/cluster/_k_means.pyx":213 + * dist += center_squared_norms[center_idx] + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: # <<<<<<<<<<<<<< + * min_dist = dist + * labels[sample_idx] = center_idx + */ + __pyx_t_11 = ((__pyx_v_min_dist == -1.0) != 0); + if (!__pyx_t_11) { + __pyx_t_29 = ((__pyx_v_dist < __pyx_v_min_dist) != 0); + __pyx_t_30 = __pyx_t_29; + } else { + __pyx_t_30 = __pyx_t_11; + } + if (__pyx_t_30) { + + /* "sklearn/cluster/_k_means.pyx":214 + * dist += x_squared_norms[sample_idx] + * if min_dist == -1 or dist < min_dist: + * min_dist = dist # <<<<<<<<<<<<<< + * labels[sample_idx] = center_idx + * if store_distances: + */ + __pyx_v_min_dist = __pyx_v_dist; + + /* "sklearn/cluster/_k_means.pyx":215 + * if min_dist == -1 or dist < min_dist: + * min_dist = dist + * labels[sample_idx] = center_idx # <<<<<<<<<<<<<< + * if store_distances: + * distances[sample_idx] = dist + */ + __pyx_t_31 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_labels.diminfo[0].strides) = __pyx_v_center_idx; + + /* "sklearn/cluster/_k_means.pyx":216 + * min_dist = dist + * labels[sample_idx] = center_idx + * if store_distances: # <<<<<<<<<<<<<< + * distances[sample_idx] = dist + * inertia += min_dist + */ + __pyx_t_30 = (__pyx_v_store_distances != 0); + if (__pyx_t_30) { + + /* "sklearn/cluster/_k_means.pyx":217 + * labels[sample_idx] = center_idx + * if store_distances: + * distances[sample_idx] = dist # <<<<<<<<<<<<<< + * inertia += min_dist + * + */ + __pyx_t_32 = __pyx_v_sample_idx; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_distances.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_distances.diminfo[0].strides) = __pyx_v_dist; + goto __pyx_L13; + } + __pyx_L13:; + goto __pyx_L12; + } + __pyx_L12:; + } + + /* "sklearn/cluster/_k_means.pyx":218 + * if store_distances: + * distances[sample_idx] = dist + * inertia += min_dist # <<<<<<<<<<<<<< + * + * return inertia + */ + __pyx_v_inertia = (__pyx_v_inertia + __pyx_v_min_dist); + } + + /* "sklearn/cluster/_k_means.pyx":220 + * inertia += min_dist + * + * return inertia # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_inertia; + goto __pyx_L0; + + /* "sklearn/cluster/_k_means.pyx":171 + * @cython.wraparound(False) + * @cython.cdivision(True) + * cpdef DOUBLE _assign_labels_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] labels, + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_WriteUnraisable("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); + __pyx_r = 0; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_center_squared_norms.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_X_data); + __Pyx_XDECREF((PyObject *)__pyx_v_X_indices); + __Pyx_XDECREF((PyObject *)__pyx_v_X_indptr); + __Pyx_XDECREF((PyObject *)__pyx_v_center_squared_norms); + __Pyx_TraceReturn(Py_None); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_6_assign_labels_csr[] = "Compute label assignment and inertia for a CSR input\n\n Return the inertia (sum of squared distances to the centers).\n "; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_assign_labels_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_X = 0; + PyArrayObject *__pyx_v_x_squared_norms = 0; + PyArrayObject *__pyx_v_centers = 0; + PyArrayObject *__pyx_v_labels = 0; + PyArrayObject *__pyx_v_distances = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_assign_labels_csr (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_x_squared_norms,&__pyx_n_s_centers,&__pyx_n_s_labels,&__pyx_n_s_distances,0}; + PyObject* values[5] = {0,0,0,0,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 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_x_squared_norms)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centers)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_assign_labels_csr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + } + __pyx_v_X = values[0]; + __pyx_v_x_squared_norms = ((PyArrayObject *)values[1]); + __pyx_v_centers = ((PyArrayObject *)values[2]); + __pyx_v_labels = ((PyArrayObject *)values[3]); + __pyx_v_distances = ((PyArrayObject *)values[4]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_assign_labels_csr", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_6_assign_labels_csr(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_assign_labels_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_labels, PyArrayObject *__pyx_v_distances) { + __Pyx_LocalBuf_ND __pyx_pybuffernd_centers; + __Pyx_Buffer __pyx_pybuffer_centers; + __Pyx_LocalBuf_ND __pyx_pybuffernd_distances; + __Pyx_Buffer __pyx_pybuffer_distances; + __Pyx_LocalBuf_ND __pyx_pybuffernd_labels; + __Pyx_Buffer __pyx_pybuffer_labels; + __Pyx_LocalBuf_ND __pyx_pybuffernd_x_squared_norms; + __Pyx_Buffer __pyx_pybuffer_x_squared_norms; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_TraceDeclarations + __Pyx_RefNannySetupContext("_assign_labels_csr", 0); + __Pyx_TraceCall("_assign_labels_csr", __pyx_f[0], 171); + __pyx_pybuffer_x_squared_norms.pybuffer.buf = NULL; + __pyx_pybuffer_x_squared_norms.refcount = 0; + __pyx_pybuffernd_x_squared_norms.data = NULL; + __pyx_pybuffernd_x_squared_norms.rcbuffer = &__pyx_pybuffer_x_squared_norms; + __pyx_pybuffer_centers.pybuffer.buf = NULL; + __pyx_pybuffer_centers.refcount = 0; + __pyx_pybuffernd_centers.data = NULL; + __pyx_pybuffernd_centers.rcbuffer = &__pyx_pybuffer_centers; + __pyx_pybuffer_labels.pybuffer.buf = NULL; + __pyx_pybuffer_labels.refcount = 0; + __pyx_pybuffernd_labels.data = NULL; + __pyx_pybuffernd_labels.rcbuffer = &__pyx_pybuffer_labels; + __pyx_pybuffer_distances.pybuffer.buf = NULL; + __pyx_pybuffer_distances.refcount = 0; + __pyx_pybuffernd_distances.data = NULL; + __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_f_7sklearn_7cluster_8_k_means__assign_labels_csr(__pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_labels, __pyx_v_distances, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __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); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("sklearn.cluster._k_means._assign_labels_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_centers.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_labels.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer); + __pyx_L2:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "sklearn/cluster/_k_means.pyx":226 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _mini_batch_update_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] counts, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_mini_batch_update_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_8_mini_batch_update_csr[] = "Incremental update of the centers for sparse MiniBatchKMeans.\n\n Parameters\n ----------\n\n X: CSR matrix, dtype float64\n The complete (pre allocated) training set as a CSR matrix.\n\n centers: array, shape (n_clusters, n_features)\n The cluster centers\n\n counts: array, shape (n_clusters,)\n The vector in which we keep track of the numbers of elements in a\n cluster\n\n Returns\n -------\n inertia: float\n The inertia of the batch prior to centers update, i.e. the sum\n distances to the closest center for each sample. This is the objective\n function being minimized by the k-means algorithm.\n\n squared_diff: float\n The sum of squared update (squared norm of the centers position\n change). If compute_squared_diff is 0, this computation is skipped and\n 0.0 is returned instead.\n\n Both squared diff and inertia are commonly used to monitor the convergence\n of the algorithm.\n "; +static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_9_mini_batch_update_csr = {__Pyx_NAMESTR("_mini_batch_update_csr"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_9_mini_batch_update_csr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_8_mini_batch_update_csr)}; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_mini_batch_update_csr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_X = 0; + CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms = 0; + PyArrayObject *__pyx_v_centers = 0; + PyArrayObject *__pyx_v_counts = 0; + PyArrayObject *__pyx_v_nearest_center = 0; + PyArrayObject *__pyx_v_old_center = 0; + int __pyx_v_compute_squared_diff; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_mini_batch_update_csr (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_x_squared_norms,&__pyx_n_s_centers,&__pyx_n_s_counts,&__pyx_n_s_nearest_center,&__pyx_n_s_old_center,&__pyx_n_s_compute_squared_diff,0}; + PyObject* values[7] = {0,0,0,0,0,0,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 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + 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 (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_squared_norms)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_x_squared_norms)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__centers)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centers)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__counts)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_counts)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: - if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nearest_center)) != 0)) kw_args--; + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nearest_center)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: - if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__old_center)) != 0)) kw_args--; + if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_old_center)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: - if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_1)) != 0)) kw_args--; + if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_compute_squared_diff)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_mini_batch_update_csr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_mini_batch_update_csr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { goto __pyx_L5_argtuple_error; @@ -3062,22 +4303,24 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr(Py __pyx_v_counts = ((PyArrayObject *)values[3]); __pyx_v_nearest_center = ((PyArrayObject *)values[4]); __pyx_v_old_center = ((PyArrayObject *)values[5]); - __pyx_v_compute_squared_diff = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_compute_squared_diff == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_compute_squared_diff = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_compute_squared_diff == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_mini_batch_update_csr", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.cluster._k_means._mini_batch_update_csr", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_counts), __pyx_ptype_5numpy_ndarray, 1, "counts", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_nearest_center), __pyx_ptype_5numpy_ndarray, 1, "nearest_center", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_old_center), __pyx_ptype_5numpy_ndarray, 1, "old_center", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_counts, __pyx_v_nearest_center, __pyx_v_old_center, __pyx_v_compute_squared_diff); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_squared_norms), __pyx_ptype_5numpy_ndarray, 1, "x_squared_norms", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_centers), __pyx_ptype_5numpy_ndarray, 1, "centers", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_counts), __pyx_ptype_5numpy_ndarray, 1, "counts", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_nearest_center), __pyx_ptype_5numpy_ndarray, 1, "nearest_center", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_old_center), __pyx_ptype_5numpy_ndarray, 1, "old_center", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_8_mini_batch_update_csr(__pyx_self, __pyx_v_X, __pyx_v_x_squared_norms, __pyx_v_centers, __pyx_v_counts, __pyx_v_nearest_center, __pyx_v_old_center, __pyx_v_compute_squared_diff); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3086,15 +4329,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr(Py return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":141 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _mini_batch_update_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=2] centers, - * np.ndarray[INT, ndim=1] counts, - */ - -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_counts, PyArrayObject *__pyx_v_nearest_center, PyArrayObject *__pyx_v_old_center, int __pyx_v_compute_squared_diff) { +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_mini_batch_update_csr(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, CYTHON_UNUSED PyArrayObject *__pyx_v_x_squared_norms, PyArrayObject *__pyx_v_centers, PyArrayObject *__pyx_v_counts, PyArrayObject *__pyx_v_nearest_center, PyArrayObject *__pyx_v_old_center, int __pyx_v_compute_squared_diff) { PyArrayObject *__pyx_v_X_data = 0; PyArrayObject *__pyx_v_X_indices = 0; PyArrayObject *__pyx_v_X_indptr = 0; @@ -3156,7 +4391,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY int __pyx_clineno = 0; __Pyx_TraceDeclarations __Pyx_RefNannySetupContext("_mini_batch_update_csr", 0); - __Pyx_TraceCall("_mini_batch_update_csr", __pyx_f[0], 141); + __Pyx_TraceCall("_mini_batch_update_csr", __pyx_f[0], 226); __pyx_pybuffer_X_data.pybuffer.buf = NULL; __pyx_pybuffer_X_data.refcount = 0; __pyx_pybuffernd_X_data.data = NULL; @@ -3191,46 +4426,46 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_pybuffernd_old_center.rcbuffer = &__pyx_pybuffer_old_center; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer, (PyObject*)__pyx_v_x_squared_norms, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_x_squared_norms.diminfo[0].strides = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x_squared_norms.diminfo[0].shape = __pyx_pybuffernd_x_squared_norms.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_v_centers, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_counts.rcbuffer->pybuffer, (PyObject*)__pyx_v_counts, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_counts.rcbuffer->pybuffer, (PyObject*)__pyx_v_counts, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_counts.diminfo[0].strides = __pyx_pybuffernd_counts.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_counts.diminfo[0].shape = __pyx_pybuffernd_counts.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_nearest_center.rcbuffer->pybuffer, (PyObject*)__pyx_v_nearest_center, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_nearest_center.rcbuffer->pybuffer, (PyObject*)__pyx_v_nearest_center, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_nearest_center.diminfo[0].strides = __pyx_pybuffernd_nearest_center.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_nearest_center.diminfo[0].shape = __pyx_pybuffernd_nearest_center.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_center.rcbuffer->pybuffer, (PyObject*)__pyx_v_old_center, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_center.rcbuffer->pybuffer, (PyObject*)__pyx_v_old_center, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_old_center.diminfo[0].strides = __pyx_pybuffernd_old_center.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_old_center.diminfo[0].shape = __pyx_pybuffernd_old_center.rcbuffer->pybuffer.shape[0]; - /* "sklearn/cluster/_k_means.pyx":178 + /* "sklearn/cluster/_k_means.pyx":263 * """ * cdef: * np.ndarray[DOUBLE, ndim=1] X_data = X.data # <<<<<<<<<<<<<< * np.ndarray[int, ndim=1] X_indices = X.indices * np.ndarray[int, ndim=1] X_indptr = X.indptr */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_data.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_data.diminfo[0].strides = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_data.diminfo[0].shape = __pyx_pybuffernd_X_data.rcbuffer->pybuffer.shape[0]; } } @@ -3238,22 +4473,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_v_X_data = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":179 + /* "sklearn/cluster/_k_means.pyx":264 * cdef: * np.ndarray[DOUBLE, ndim=1] X_data = X.data * np.ndarray[int, ndim=1] X_indices = X.indices # <<<<<<<<<<<<<< * np.ndarray[int, ndim=1] X_indptr = X.indptr * unsigned int n_samples = X.shape[0] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_indices.diminfo[0].strides = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indices.diminfo[0].shape = __pyx_pybuffernd_X_indices.rcbuffer->pybuffer.shape[0]; } } @@ -3261,22 +4496,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_v_X_indices = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":180 + /* "sklearn/cluster/_k_means.pyx":265 * np.ndarray[DOUBLE, ndim=1] X_data = X.data * np.ndarray[int, ndim=1] X_indices = X.indices * np.ndarray[int, ndim=1] X_indptr = X.indptr # <<<<<<<<<<<<<< * unsigned int n_samples = X.shape[0] * unsigned int n_clusters = centers.shape[0] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indptr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_X_indptr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_X_indptr.diminfo[0].strides = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X_indptr.diminfo[0].shape = __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.shape[0]; } } @@ -3284,23 +4519,23 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_v_X_indptr = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":181 + /* "sklearn/cluster/_k_means.pyx":266 * np.ndarray[int, ndim=1] X_indices = X.indices * np.ndarray[int, ndim=1] X_indptr = X.indptr * unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_5); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_5); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_n_samples = __pyx_t_6; - /* "sklearn/cluster/_k_means.pyx":182 + /* "sklearn/cluster/_k_means.pyx":267 * np.ndarray[int, ndim=1] X_indptr = X.indptr * unsigned int n_samples = X.shape[0] * unsigned int n_clusters = centers.shape[0] # <<<<<<<<<<<<<< @@ -3309,7 +4544,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_v_n_clusters = (__pyx_v_centers->dimensions[0]); - /* "sklearn/cluster/_k_means.pyx":183 + /* "sklearn/cluster/_k_means.pyx":268 * unsigned int n_samples = X.shape[0] * unsigned int n_clusters = centers.shape[0] * unsigned int n_features = centers.shape[1] # <<<<<<<<<<<<<< @@ -3318,7 +4553,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_v_n_features = (__pyx_v_centers->dimensions[1]); - /* "sklearn/cluster/_k_means.pyx":189 + /* "sklearn/cluster/_k_means.pyx":274 * int old_count, new_count * DOUBLE center_diff * DOUBLE squared_diff = 0.0 # <<<<<<<<<<<<<< @@ -3327,7 +4562,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_v_squared_diff = 0.0; - /* "sklearn/cluster/_k_means.pyx":192 + /* "sklearn/cluster/_k_means.pyx":277 * * # move centers to the mean of both old and newly assigned samples * for center_idx in range(n_clusters): # <<<<<<<<<<<<<< @@ -3338,7 +4573,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { __pyx_v_center_idx = __pyx_t_7; - /* "sklearn/cluster/_k_means.pyx":193 + /* "sklearn/cluster/_k_means.pyx":278 * # move centers to the mean of both old and newly assigned samples * for center_idx in range(n_clusters): * old_count = counts[center_idx] # <<<<<<<<<<<<<< @@ -3348,7 +4583,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_8 = __pyx_v_center_idx; __pyx_v_old_count = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_counts.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_counts.diminfo[0].strides)); - /* "sklearn/cluster/_k_means.pyx":194 + /* "sklearn/cluster/_k_means.pyx":279 * for center_idx in range(n_clusters): * old_count = counts[center_idx] * new_count = old_count # <<<<<<<<<<<<<< @@ -3357,7 +4592,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_v_new_count = __pyx_v_old_count; - /* "sklearn/cluster/_k_means.pyx":197 + /* "sklearn/cluster/_k_means.pyx":282 * * # count the number of samples assigned to this center * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< @@ -3368,7 +4603,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_sample_idx = __pyx_t_10; - /* "sklearn/cluster/_k_means.pyx":198 + /* "sklearn/cluster/_k_means.pyx":283 * # count the number of samples assigned to this center * for sample_idx in range(n_samples): * if nearest_center[sample_idx] == center_idx: # <<<<<<<<<<<<<< @@ -3379,7 +4614,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_nearest_center.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_nearest_center.diminfo[0].strides)) == __pyx_v_center_idx) != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":199 + /* "sklearn/cluster/_k_means.pyx":284 * for sample_idx in range(n_samples): * if nearest_center[sample_idx] == center_idx: * new_count += 1 # <<<<<<<<<<<<<< @@ -3392,7 +4627,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_L7:; } - /* "sklearn/cluster/_k_means.pyx":201 + /* "sklearn/cluster/_k_means.pyx":286 * new_count += 1 * * if new_count == old_count: # <<<<<<<<<<<<<< @@ -3402,7 +4637,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = ((__pyx_v_new_count == __pyx_v_old_count) != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":203 + /* "sklearn/cluster/_k_means.pyx":288 * if new_count == old_count: * # no new sample: leave this center as it stands * continue # <<<<<<<<<<<<<< @@ -3410,11 +4645,9 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY * # rescale the old center to reflect it previous accumulated */ goto __pyx_L3_continue; - goto __pyx_L8; } - __pyx_L8:; - /* "sklearn/cluster/_k_means.pyx":207 + /* "sklearn/cluster/_k_means.pyx":292 * # rescale the old center to reflect it previous accumulated * # weight w.r.t. the new data that will be incrementally contributed * if compute_squared_diff: # <<<<<<<<<<<<<< @@ -3424,22 +4657,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = (__pyx_v_compute_squared_diff != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":208 + /* "sklearn/cluster/_k_means.pyx":293 * # weight w.r.t. the new data that will be incrementally contributed * if compute_squared_diff: * old_center[:] = centers[center_idx] # <<<<<<<<<<<<<< * centers[center_idx] *= old_count * */ - __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_center_idx, sizeof(unsigned int)+1, PyLong_FromUnsignedLong, 0, 0, 0); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_center_idx, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_PyObject_SetSlice(((PyObject *)__pyx_v_old_center), __pyx_t_5, 0, 0, NULL, NULL, &__pyx_k_slice_2, 0, 0, 0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_PyObject_SetSlice(((PyObject *)__pyx_v_old_center), __pyx_t_5, 0, 0, NULL, NULL, &__pyx_slice_, 0, 0, 0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L9; } __pyx_L9:; - /* "sklearn/cluster/_k_means.pyx":209 + /* "sklearn/cluster/_k_means.pyx":294 * if compute_squared_diff: * old_center[:] = centers[center_idx] * centers[center_idx] *= old_count # <<<<<<<<<<<<<< @@ -3447,18 +4680,18 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY * # iterate of over samples assigned to this cluster to move the center */ __pyx_t_9 = __pyx_v_center_idx; - __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_9, sizeof(unsigned int)+1, PyLong_FromUnsignedLong, 0, 0, 0); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_9, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyInt_FromLong(__pyx_v_old_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_old_count); 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_13 = PyNumber_InPlaceMultiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = PyNumber_InPlaceMultiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_9, __pyx_t_13, sizeof(unsigned int)+1, PyLong_FromUnsignedLong, 0, 0, 0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_9, __pyx_t_13, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - /* "sklearn/cluster/_k_means.pyx":213 + /* "sklearn/cluster/_k_means.pyx":298 * # iterate of over samples assigned to this cluster to move the center * # location by inplace summation * for sample_idx in range(n_samples): # <<<<<<<<<<<<<< @@ -3469,7 +4702,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_sample_idx = __pyx_t_10; - /* "sklearn/cluster/_k_means.pyx":214 + /* "sklearn/cluster/_k_means.pyx":299 * # location by inplace summation * for sample_idx in range(n_samples): * if nearest_center[sample_idx] != center_idx: # <<<<<<<<<<<<<< @@ -3480,7 +4713,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_nearest_center.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_nearest_center.diminfo[0].strides)) != __pyx_v_center_idx) != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":215 + /* "sklearn/cluster/_k_means.pyx":300 * for sample_idx in range(n_samples): * if nearest_center[sample_idx] != center_idx: * continue # <<<<<<<<<<<<<< @@ -3488,11 +4721,9 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY * # inplace sum with new samples that are members of this cluster */ goto __pyx_L10_continue; - goto __pyx_L12; } - __pyx_L12:; - /* "sklearn/cluster/_k_means.pyx":220 + /* "sklearn/cluster/_k_means.pyx":305 * # and update of the incremental squared difference update of the * # center position * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): # <<<<<<<<<<<<<< @@ -3505,7 +4736,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY for (__pyx_t_18 = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_X_indptr.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_X_indptr.diminfo[0].strides)); __pyx_t_18 < __pyx_t_16; __pyx_t_18+=1) { __pyx_v_k = __pyx_t_18; - /* "sklearn/cluster/_k_means.pyx":221 + /* "sklearn/cluster/_k_means.pyx":306 * # center position * for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): * centers[center_idx, X_indices[k]] += X_data[k] # <<<<<<<<<<<<<< @@ -3521,7 +4752,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_L10_continue:; } - /* "sklearn/cluster/_k_means.pyx":224 + /* "sklearn/cluster/_k_means.pyx":309 * * # inplace rescale center with updated count * if new_count > old_count: # <<<<<<<<<<<<<< @@ -3531,7 +4762,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = ((__pyx_v_new_count > __pyx_v_old_count) != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":226 + /* "sklearn/cluster/_k_means.pyx":311 * if new_count > old_count: * # update the count statistics for this center * counts[center_idx] = new_count # <<<<<<<<<<<<<< @@ -3541,7 +4772,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_9 = __pyx_v_center_idx; *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_counts.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_counts.diminfo[0].strides) = __pyx_v_new_count; - /* "sklearn/cluster/_k_means.pyx":229 + /* "sklearn/cluster/_k_means.pyx":314 * * # re-scale the updated center with the total new counts * centers[center_idx] /= new_count # <<<<<<<<<<<<<< @@ -3549,18 +4780,18 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY * # update the incremental computation of the squared total */ __pyx_t_10 = __pyx_v_center_idx; - __pyx_t_13 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_10, sizeof(unsigned int)+1, PyLong_FromUnsignedLong, 0, 0, 0); if (!__pyx_t_13) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_10, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_13); - __pyx_t_1 = PyInt_FromLong(__pyx_v_new_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_new_count); 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_5 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_13, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_13, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_10, __pyx_t_5, sizeof(unsigned int)+1, PyLong_FromUnsignedLong, 0, 0, 0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_10, __pyx_t_5, unsigned int, 0, __Pyx_PyInt_From_unsigned_int, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "sklearn/cluster/_k_means.pyx":233 + /* "sklearn/cluster/_k_means.pyx":318 * # update the incremental computation of the squared total * # centers position change * if compute_squared_diff: # <<<<<<<<<<<<<< @@ -3570,7 +4801,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_t_12 = (__pyx_v_compute_squared_diff != 0); if (__pyx_t_12) { - /* "sklearn/cluster/_k_means.pyx":234 + /* "sklearn/cluster/_k_means.pyx":319 * # centers position change * if compute_squared_diff: * for feature_idx in range(n_features): # <<<<<<<<<<<<<< @@ -3581,7 +4812,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_10; __pyx_t_18+=1) { __pyx_v_feature_idx = __pyx_t_18; - /* "sklearn/cluster/_k_means.pyx":235 + /* "sklearn/cluster/_k_means.pyx":320 * if compute_squared_diff: * for feature_idx in range(n_features): * squared_diff += (old_center[feature_idx] # <<<<<<<<<<<<<< @@ -3590,7 +4821,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_t_23 = __pyx_v_feature_idx; - /* "sklearn/cluster/_k_means.pyx":236 + /* "sklearn/cluster/_k_means.pyx":321 * for feature_idx in range(n_features): * squared_diff += (old_center[feature_idx] * - centers[center_idx, feature_idx]) ** 2 # <<<<<<<<<<<<<< @@ -3599,6 +4830,14 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY */ __pyx_t_24 = __pyx_v_center_idx; __pyx_t_25 = __pyx_v_feature_idx; + + /* "sklearn/cluster/_k_means.pyx":320 + * if compute_squared_diff: + * for feature_idx in range(n_features): + * squared_diff += (old_center[feature_idx] # <<<<<<<<<<<<<< + * - centers[center_idx, feature_idx]) ** 2 + * + */ __pyx_v_squared_diff = (__pyx_v_squared_diff + pow(((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_old_center.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_old_center.diminfo[0].strides)) - (*__Pyx_BufPtrStrided2d(__pyx_t_7sklearn_7cluster_8_k_means_DOUBLE *, __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_centers.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_centers.diminfo[1].strides))), 2.0)); } goto __pyx_L16; @@ -3610,7 +4849,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY __pyx_L3_continue:; } - /* "sklearn/cluster/_k_means.pyx":238 + /* "sklearn/cluster/_k_means.pyx":323 * - centers[center_idx, feature_idx]) ** 2 * * return squared_diff # <<<<<<<<<<<<<< @@ -3618,14 +4857,21 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_squared_diff); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_squared_diff); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "sklearn/cluster/_k_means.pyx":226 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _mini_batch_update_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=2] centers, + * np.ndarray[INT, ndim=1] counts, + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); @@ -3663,11 +4909,19 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_4_mini_batch_update_csr(CY return __pyx_r; } +/* "sklearn/cluster/_k_means.pyx":329 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] labels, int n_clusters, + * np.ndarray[DOUBLE, ndim=1] distances): + */ + /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_7cluster_8_k_means_6_centers_dense[] = "M step of the K-means EM algorithm\n\n Computation of cluster centers / means.\n\n Parameters\n ----------\n X: array-like, shape (n_samples, n_features)\n\n labels: array of integers, shape (n_samples)\n Current label assignment\n\n n_clusters: int\n Number of desired clusters\n\n distances: array-like, shape (n_samples)\n Distance to closest cluster for each sample.\n\n Returns\n -------\n centers: array, shape (n_clusters, n_features)\n The resulting centers\n "; -static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_7_centers_dense = {__Pyx_NAMESTR("_centers_dense"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_6_centers_dense)}; -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_11_centers_dense(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_10_centers_dense[] = "M step of the K-means EM algorithm\n\n Computation of cluster centers / means.\n\n Parameters\n ----------\n X: array-like, shape (n_samples, n_features)\n\n labels: array of integers, shape (n_samples)\n Current label assignment\n\n n_clusters: int\n Number of desired clusters\n\n distances: array-like, shape (n_samples)\n Distance to closest cluster for each sample.\n\n Returns\n -------\n centers: array, shape (n_clusters, n_features)\n The resulting centers\n "; +static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_11_centers_dense = {__Pyx_NAMESTR("_centers_dense"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_11_centers_dense, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_10_centers_dense)}; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_11_centers_dense(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_X = 0; PyArrayObject *__pyx_v_labels = 0; int __pyx_v_n_clusters; @@ -3679,7 +4933,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject * __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_centers_dense (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__labels,&__pyx_n_s__n_clusters,&__pyx_n_s__distances,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_labels,&__pyx_n_s_n_clusters,&__pyx_n_s_distances,0}; PyObject* values[4] = {0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -3695,26 +4949,26 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject * 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--; + 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__labels)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_clusters)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n_clusters)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__distances)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_centers_dense") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_centers_dense") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; @@ -3726,21 +4980,23 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject * } __pyx_v_X = ((PyArrayObject *)values[0]); __pyx_v_labels = ((PyArrayObject *)values[1]); - __pyx_v_n_clusters = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_n_clusters == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_clusters = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_n_clusters == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_distances = ((PyArrayObject *)values[3]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_dense", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.cluster._k_means._centers_dense", __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 = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(__pyx_self, __pyx_v_X, __pyx_v_labels, __pyx_v_n_clusters, __pyx_v_distances); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_10_centers_dense(__pyx_self, __pyx_v_X, __pyx_v_labels, __pyx_v_n_clusters, __pyx_v_distances); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3749,15 +5005,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_7_centers_dense(PyObject * return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":244 - * @cython.wraparound(False) - * @cython.cdivision(True) - * def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< - * np.ndarray[INT, ndim=1] labels, int n_clusters, - * np.ndarray[DOUBLE, ndim=1] distances): - */ - -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, int __pyx_v_n_clusters, PyArrayObject *__pyx_v_distances) { +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_10_centers_dense(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, int __pyx_v_n_clusters, PyArrayObject *__pyx_v_distances) { int __pyx_v_n_samples; int __pyx_v_n_features; int __pyx_v_i; @@ -3803,7 +5051,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU int __pyx_clineno = 0; __Pyx_TraceDeclarations __Pyx_RefNannySetupContext("_centers_dense", 0); - __Pyx_TraceCall("_centers_dense", __pyx_f[0], 244); + __Pyx_TraceCall("_centers_dense", __pyx_f[0], 329); __pyx_pybuffer_centers.pybuffer.buf = NULL; __pyx_pybuffer_centers.refcount = 0; __pyx_pybuffernd_centers.data = NULL; @@ -3822,21 +5070,21 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; - /* "sklearn/cluster/_k_means.pyx":271 + /* "sklearn/cluster/_k_means.pyx":356 * ## TODO: add support for CSR input * cdef int n_samples, n_features * n_samples = X.shape[0] # <<<<<<<<<<<<<< @@ -3845,7 +5093,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU */ __pyx_v_n_samples = (__pyx_v_X->dimensions[0]); - /* "sklearn/cluster/_k_means.pyx":272 + /* "sklearn/cluster/_k_means.pyx":357 * cdef int n_samples, n_features * n_samples = X.shape[0] * n_features = X.shape[1] # <<<<<<<<<<<<<< @@ -3854,23 +5102,23 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU */ __pyx_v_n_features = (__pyx_v_X->dimensions[1]); - /* "sklearn/cluster/_k_means.pyx":274 + /* "sklearn/cluster/_k_means.pyx":359 * n_features = X.shape[1] * cdef int i, j, c * cdef np.ndarray[DOUBLE, ndim=2] centers = np.zeros((n_clusters, n_features)) # <<<<<<<<<<<<<< * n_samples_in_cluster = bincount(labels, minlength=n_clusters) * empty_clusters = np.where(n_samples_in_cluster == 0)[0] */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); 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 = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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 = PyInt_FromLong(__pyx_v_n_clusters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_clusters); 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_3 = PyInt_FromLong(__pyx_v_n_features); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_features); 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_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); 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); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -3878,22 +5126,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); 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); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); 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_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__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 = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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 = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_5 = ((PyArrayObject *)__pyx_t_4); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_centers = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; } } @@ -3901,86 +5149,86 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU __pyx_v_centers = ((PyArrayObject *)__pyx_t_4); __pyx_t_4 = 0; - /* "sklearn/cluster/_k_means.pyx":275 + /* "sklearn/cluster/_k_means.pyx":360 * cdef int i, j, c * cdef np.ndarray[DOUBLE, ndim=2] centers = np.zeros((n_clusters, n_features)) * n_samples_in_cluster = bincount(labels, minlength=n_clusters) # <<<<<<<<<<<<<< * empty_clusters = np.where(n_samples_in_cluster == 0)[0] * # maybe also relocate small clusters? */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__bincount); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_bincount); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_labels)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_labels)); __Pyx_GIVEREF(((PyObject *)__pyx_v_labels)); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = PyInt_FromLong(__pyx_v_n_clusters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_clusters); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__minlength), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_minlength, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_n_samples_in_cluster = __pyx_t_1; __pyx_t_1 = 0; - /* "sklearn/cluster/_k_means.pyx":276 + /* "sklearn/cluster/_k_means.pyx":361 * cdef np.ndarray[DOUBLE, ndim=2] centers = np.zeros((n_clusters, n_features)) * n_samples_in_cluster = bincount(labels, minlength=n_clusters) * empty_clusters = np.where(n_samples_in_cluster == 0)[0] # <<<<<<<<<<<<<< * # maybe also relocate small clusters? * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__where); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_where); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_v_n_samples_in_cluster, __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_n_samples_in_cluster, __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_empty_clusters = __pyx_t_3; __pyx_t_3 = 0; - /* "sklearn/cluster/_k_means.pyx":279 + /* "sklearn/cluster/_k_means.pyx":364 * # maybe also relocate small clusters? * * if len(empty_clusters): # <<<<<<<<<<<<<< * # find points to reassign empty clusters to * far_from_centers = distances.argsort()[::-1] */ - __pyx_t_6 = PyObject_Length(__pyx_v_empty_clusters); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Length(__pyx_v_empty_clusters); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = (__pyx_t_6 != 0); if (__pyx_t_7) { - /* "sklearn/cluster/_k_means.pyx":281 + /* "sklearn/cluster/_k_means.pyx":366 * if len(empty_clusters): * # find points to reassign empty clusters to * far_from_centers = distances.argsort()[::-1] # <<<<<<<<<<<<<< * * for i, cluster_id in enumerate(empty_clusters): */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distances), __pyx_n_s__argsort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distances), __pyx_n_s_argsort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetItem(__pyx_t_1, __pyx_k_slice_3); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetItem(__pyx_t_1, __pyx_slice__2); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_far_from_centers = __pyx_t_3; @@ -3989,7 +5237,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU } __pyx_L3:; - /* "sklearn/cluster/_k_means.pyx":283 + /* "sklearn/cluster/_k_means.pyx":368 * far_from_centers = distances.argsort()[::-1] * * for i, cluster_id in enumerate(empty_clusters): # <<<<<<<<<<<<<< @@ -4001,7 +5249,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU __pyx_t_3 = __pyx_v_empty_clusters; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_empty_clusters); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_empty_clusters); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; } @@ -4009,72 +5257,71 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_3)) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif } else { __pyx_t_1 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + 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 = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_1); } - __Pyx_XDECREF(__pyx_v_cluster_id); - __pyx_v_cluster_id = __pyx_t_1; + __Pyx_XDECREF_SET(__pyx_v_cluster_id, __pyx_t_1); __pyx_t_1 = 0; __pyx_v_i = __pyx_t_8; __pyx_t_8 = (__pyx_t_8 + 1); - /* "sklearn/cluster/_k_means.pyx":285 + /* "sklearn/cluster/_k_means.pyx":370 * for i, cluster_id in enumerate(empty_clusters): * # XXX two relocated clusters could be close to each other * new_center = X[far_from_centers[i]] # <<<<<<<<<<<<<< * centers[cluster_id] = new_center * n_samples_in_cluster[cluster_id] = 1 */ - if (unlikely(!__pyx_v_far_from_centers)) { __Pyx_RaiseUnboundLocalError("far_from_centers"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_far_from_centers, __pyx_v_i, sizeof(int), PyInt_FromLong, 0, 0, 0); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_v_far_from_centers)) { __Pyx_RaiseUnboundLocalError("far_from_centers"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_far_from_centers, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_t_1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_X), __pyx_t_1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_v_new_center); - __pyx_v_new_center = __pyx_t_2; + __Pyx_XDECREF_SET(__pyx_v_new_center, __pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":286 + /* "sklearn/cluster/_k_means.pyx":371 * # XXX two relocated clusters could be close to each other * new_center = X[far_from_centers[i]] * centers[cluster_id] = new_center # <<<<<<<<<<<<<< * n_samples_in_cluster[cluster_id] = 1 * */ - if (PyObject_SetItem(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, __pyx_v_new_center) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, __pyx_v_new_center) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/cluster/_k_means.pyx":287 + /* "sklearn/cluster/_k_means.pyx":372 * new_center = X[far_from_centers[i]] * centers[cluster_id] = new_center * n_samples_in_cluster[cluster_id] = 1 # <<<<<<<<<<<<<< * * for i in range(n_samples): */ - if (PyObject_SetItem(__pyx_v_n_samples_in_cluster, __pyx_v_cluster_id, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(PyObject_SetItem(__pyx_v_n_samples_in_cluster, __pyx_v_cluster_id, __pyx_int_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/cluster/_k_means.pyx":289 + /* "sklearn/cluster/_k_means.pyx":374 * n_samples_in_cluster[cluster_id] = 1 * * for i in range(n_samples): # <<<<<<<<<<<<<< @@ -4085,7 +5332,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_8; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "sklearn/cluster/_k_means.pyx":290 + /* "sklearn/cluster/_k_means.pyx":375 * * for i in range(n_samples): * for j in range(n_features): # <<<<<<<<<<<<<< @@ -4096,12 +5343,12 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_j = __pyx_t_12; - /* "sklearn/cluster/_k_means.pyx":291 + /* "sklearn/cluster/_k_means.pyx":376 * for i in range(n_samples): * for j in range(n_features): * centers[labels[i], j] += X[i, j] # <<<<<<<<<<<<<< * - * centers /= n_samples_in_cluster[:, np.newaxis] + * # todo center computation needs to be aware of the distance measure */ __pyx_t_13 = __pyx_v_i; __pyx_t_14 = __pyx_v_j; @@ -4112,33 +5359,33 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU } } - /* "sklearn/cluster/_k_means.pyx":293 - * centers[labels[i], j] += X[i, j] + /* "sklearn/cluster/_k_means.pyx":379 * + * # todo center computation needs to be aware of the distance measure * centers /= n_samples_in_cluster[:, np.newaxis] # <<<<<<<<<<<<<< * * return centers */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__newaxis); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_newaxis); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_k_slice_4); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_k_slice_4); - __Pyx_GIVEREF(__pyx_k_slice_4); + __Pyx_INCREF(__pyx_slice__3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_slice__3); + __Pyx_GIVEREF(__pyx_slice__3); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetItem(__pyx_v_n_samples_in_cluster, ((PyObject *)__pyx_t_3)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetItem(__pyx_v_n_samples_in_cluster, __pyx_t_3); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_centers), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_centers), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __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 = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_5 = ((PyArrayObject *)__pyx_t_3); { __Pyx_BufFmt_StackElem __pyx_stack[1]; @@ -4154,14 +5401,13 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU } } __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_centers)); - __pyx_v_centers = ((PyArrayObject *)__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_centers, ((PyArrayObject *)__pyx_t_3)); __pyx_t_3 = 0; - /* "sklearn/cluster/_k_means.pyx":295 + /* "sklearn/cluster/_k_means.pyx":381 * centers /= n_samples_in_cluster[:, np.newaxis] * * return centers # <<<<<<<<<<<<<< @@ -4173,8 +5419,15 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU __pyx_r = ((PyObject *)__pyx_v_centers); goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "sklearn/cluster/_k_means.pyx":329 + * @cython.wraparound(False) + * @cython.cdivision(True) + * def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< + * np.ndarray[INT, ndim=1] labels, int n_clusters, + * np.ndarray[DOUBLE, ndim=1] distances): + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); @@ -4208,11 +5461,19 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_6_centers_dense(CYTHON_UNU return __pyx_r; } +/* "sklearn/cluster/_k_means.pyx":384 + * + * + * def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=1] distances): + * """M step of the K-means EM algorithm + */ + /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_7cluster_8_k_means_8_centers_sparse[] = "M step of the K-means EM algorithm\n\n Computation of cluster centers / means.\n\n Parameters\n ----------\n X: scipy.sparse.csr_matrix, shape (n_samples, n_features)\n\n labels: array of integers, shape (n_samples)\n Current label assignment\n\n n_clusters: int\n Number of desired clusters\n\n distances: array-like, shape (n_samples)\n Distance to closest cluster for each sample.\n\n Returns\n -------\n centers: array, shape (n_clusters, n_features)\n The resulting centers\n "; -static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_9_centers_sparse = {__Pyx_NAMESTR("_centers_sparse"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_8_centers_sparse)}; -static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_13_centers_sparse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_7cluster_8_k_means_12_centers_sparse[] = "M step of the K-means EM algorithm\n\n Computation of cluster centers / means.\n\n Parameters\n ----------\n X: scipy.sparse.csr_matrix, shape (n_samples, n_features)\n\n labels: array of integers, shape (n_samples)\n Current label assignment\n\n n_clusters: int\n Number of desired clusters\n\n distances: array-like, shape (n_samples)\n Distance to closest cluster for each sample.\n\n Returns\n -------\n centers: array, shape (n_clusters, n_features)\n The resulting centers\n "; +static PyMethodDef __pyx_mdef_7sklearn_7cluster_8_k_means_13_centers_sparse = {__Pyx_NAMESTR("_centers_sparse"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_13_centers_sparse, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_12_centers_sparse)}; +static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_13_centers_sparse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_X = 0; PyArrayObject *__pyx_v_labels = 0; PyObject *__pyx_v_n_clusters = 0; @@ -4224,7 +5485,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_centers_sparse (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__labels,&__pyx_n_s__n_clusters,&__pyx_n_s__distances,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_labels,&__pyx_n_s_n_clusters,&__pyx_n_s_distances,0}; PyObject* values[4] = {0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -4240,26 +5501,26 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject 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--; + 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__labels)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_labels)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_clusters)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n_clusters)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__distances)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_distances)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_centers_sparse") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_centers_sparse") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; @@ -4276,15 +5537,17 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_centers_sparse", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.cluster._k_means._centers_sparse", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(__pyx_self, __pyx_v_X, __pyx_v_labels, __pyx_v_n_clusters, __pyx_v_distances); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_labels), __pyx_ptype_5numpy_ndarray, 1, "labels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_distances), __pyx_ptype_5numpy_ndarray, 1, "distances", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_7cluster_8_k_means_12_centers_sparse(__pyx_self, __pyx_v_X, __pyx_v_labels, __pyx_v_n_clusters, __pyx_v_distances); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -4293,15 +5556,7 @@ static PyObject *__pyx_pw_7sklearn_7cluster_8_k_means_9_centers_sparse(PyObject return __pyx_r; } -/* "sklearn/cluster/_k_means.pyx":298 - * - * - * def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, # <<<<<<<<<<<<<< - * np.ndarray[DOUBLE, ndim=1] distances): - * """M step of the K-means EM algorithm - */ - -static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, PyObject *__pyx_v_n_clusters, PyArrayObject *__pyx_v_distances) { +static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_12_centers_sparse(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_labels, PyObject *__pyx_v_n_clusters, PyArrayObject *__pyx_v_distances) { PyObject *__pyx_v_n_features = NULL; npy_intp __pyx_v_cluster_id; PyArrayObject *__pyx_v_data = 0; @@ -4360,7 +5615,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN int __pyx_clineno = 0; __Pyx_TraceDeclarations __Pyx_RefNannySetupContext("_centers_sparse", 0); - __Pyx_TraceCall("_centers_sparse", __pyx_f[0], 298); + __Pyx_TraceCall("_centers_sparse", __pyx_f[0], 384); __pyx_pybuffer_data.pybuffer.buf = NULL; __pyx_pybuffer_data.refcount = 0; __pyx_pybuffernd_data.data = NULL; @@ -4399,46 +5654,46 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_pybuffernd_distances.rcbuffer = &__pyx_pybuffer_distances; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_labels, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_INT, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_labels.diminfo[0].strides = __pyx_pybuffernd_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_labels.diminfo[0].shape = __pyx_pybuffernd_labels.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_distances.diminfo[0].strides = __pyx_pybuffernd_distances.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances.diminfo[0].shape = __pyx_pybuffernd_distances.rcbuffer->pybuffer.shape[0]; - /* "sklearn/cluster/_k_means.pyx":322 + /* "sklearn/cluster/_k_means.pyx":408 * The resulting centers * """ * n_features = X.shape[1] # <<<<<<<<<<<<<< * * cdef np.npy_intp cluster_id */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_n_features = __pyx_t_2; __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":326 + /* "sklearn/cluster/_k_means.pyx":412 * cdef np.npy_intp cluster_id * * cdef np.ndarray[DOUBLE, ndim=1] data = X.data # <<<<<<<<<<<<<< * cdef np.ndarray[int, ndim=1] indices = X.indices * cdef np.ndarray[int, ndim=1] indptr = X.indptr */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_data.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0]; } } @@ -4446,22 +5701,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_data = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":327 + /* "sklearn/cluster/_k_means.pyx":413 * * cdef np.ndarray[DOUBLE, ndim=1] data = X.data * cdef np.ndarray[int, ndim=1] indices = X.indices # <<<<<<<<<<<<<< * cdef np.ndarray[int, ndim=1] indptr = X.indptr * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indices); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_indices.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_indices.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_indices.diminfo[0].strides = __pyx_pybuffernd_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_indices.diminfo[0].shape = __pyx_pybuffernd_indices.rcbuffer->pybuffer.shape[0]; } } @@ -4469,22 +5724,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_indices = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":328 + /* "sklearn/cluster/_k_means.pyx":414 * cdef np.ndarray[DOUBLE, ndim=1] data = X.data * cdef np.ndarray[int, ndim=1] indices = X.indices * cdef np.ndarray[int, ndim=1] indptr = X.indptr # <<<<<<<<<<<<<< * * cdef np.ndarray[DOUBLE, ndim=2, mode="c"] centers = \ */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indptr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_5 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_indptr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_indptr.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_indptr.diminfo[0].strides = __pyx_pybuffernd_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_indptr.diminfo[0].shape = __pyx_pybuffernd_indptr.rcbuffer->pybuffer.shape[0]; } } @@ -4492,19 +5747,19 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_indptr = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":331 + /* "sklearn/cluster/_k_means.pyx":417 * * cdef np.ndarray[DOUBLE, ndim=2, mode="c"] centers = \ * np.zeros((n_clusters, n_features)) # <<<<<<<<<<<<<< * cdef np.ndarray[np.npy_intp, ndim=1] far_from_centers * cdef np.ndarray[np.npy_intp, ndim=1, mode="c"] n_samples_in_cluster = \ */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __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 = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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 = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_n_clusters); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_n_clusters); @@ -4512,22 +5767,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __Pyx_INCREF(__pyx_v_n_features); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_n_features); __Pyx_GIVEREF(__pyx_v_n_features); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 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 = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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 = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_centers.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_7cluster_8_k_means_DOUBLE, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) { __pyx_v_centers = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_centers.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; } } @@ -4535,35 +5790,35 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_centers = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/cluster/_k_means.pyx":334 + /* "sklearn/cluster/_k_means.pyx":420 * cdef np.ndarray[np.npy_intp, ndim=1] far_from_centers * cdef np.ndarray[np.npy_intp, ndim=1, mode="c"] n_samples_in_cluster = \ * bincount(labels, minlength=n_clusters) # <<<<<<<<<<<<<< * cdef np.ndarray[np.npy_intp, ndim=1, mode="c"] empty_clusters = \ * np.where(n_samples_in_cluster == 0)[0] */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__bincount); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_bincount); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(((PyObject *)__pyx_v_labels)); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_labels)); __Pyx_GIVEREF(((PyObject *)__pyx_v_labels)); - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__minlength), __pyx_v_n_clusters) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_minlength, __pyx_v_n_clusters) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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 = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_9 = ((PyArrayObject *)__pyx_t_8); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_n_samples_in_cluster.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn_npy_intp, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_n_samples_in_cluster = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_n_samples_in_cluster.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_n_samples_in_cluster.diminfo[0].strides = __pyx_pybuffernd_n_samples_in_cluster.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_n_samples_in_cluster.diminfo[0].shape = __pyx_pybuffernd_n_samples_in_cluster.rcbuffer->pybuffer.shape[0]; } } @@ -4571,38 +5826,38 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_n_samples_in_cluster = ((PyArrayObject *)__pyx_t_8); __pyx_t_8 = 0; - /* "sklearn/cluster/_k_means.pyx":336 + /* "sklearn/cluster/_k_means.pyx":422 * bincount(labels, minlength=n_clusters) * cdef np.ndarray[np.npy_intp, ndim=1, mode="c"] empty_clusters = \ * np.where(n_samples_in_cluster == 0)[0] # <<<<<<<<<<<<<< * * # maybe also relocate small clusters? */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s__where); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_where); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_v_n_samples_in_cluster), __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_RichCompare(((PyObject *)__pyx_v_n_samples_in_cluster), __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_8, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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 = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_10 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_empty_clusters.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn_npy_intp, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) { __pyx_v_empty_clusters = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_empty_clusters.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_empty_clusters.diminfo[0].strides = __pyx_pybuffernd_empty_clusters.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_empty_clusters.diminfo[0].shape = __pyx_pybuffernd_empty_clusters.rcbuffer->pybuffer.shape[0]; } } @@ -4610,7 +5865,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_v_empty_clusters = ((PyArrayObject *)__pyx_t_6); __pyx_t_6 = 0; - /* "sklearn/cluster/_k_means.pyx":340 + /* "sklearn/cluster/_k_means.pyx":426 * # maybe also relocate small clusters? * * if empty_clusters.shape[0] > 0: # <<<<<<<<<<<<<< @@ -4620,22 +5875,22 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_t_11 = (((__pyx_v_empty_clusters->dimensions[0]) > 0) != 0); if (__pyx_t_11) { - /* "sklearn/cluster/_k_means.pyx":342 + /* "sklearn/cluster/_k_means.pyx":428 * if empty_clusters.shape[0] > 0: * # find points to reassign empty clusters to * far_from_centers = distances.argsort()[::-1] # <<<<<<<<<<<<<< * * for i in range(empty_clusters.shape[0]): */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distances), __pyx_n_s__argsort); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distances), __pyx_n_s_argsort); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_6, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_GetItem(__pyx_t_8, __pyx_k_slice_5); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetItem(__pyx_t_8, __pyx_slice__4); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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 = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_12 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; @@ -4651,7 +5906,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } } __pyx_pybuffernd_far_from_centers.diminfo[0].strides = __pyx_pybuffernd_far_from_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_far_from_centers.diminfo[0].shape = __pyx_pybuffernd_far_from_centers.rcbuffer->pybuffer.shape[0]; - if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_12 = 0; __pyx_v_far_from_centers = ((PyArrayObject *)__pyx_t_6); @@ -4660,7 +5915,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } __pyx_L3:; - /* "sklearn/cluster/_k_means.pyx":344 + /* "sklearn/cluster/_k_means.pyx":430 * far_from_centers = distances.argsort()[::-1] * * for i in range(empty_clusters.shape[0]): # <<<<<<<<<<<<<< @@ -4671,7 +5926,7 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) { __pyx_v_i = __pyx_t_18; - /* "sklearn/cluster/_k_means.pyx":345 + /* "sklearn/cluster/_k_means.pyx":431 * * for i in range(empty_clusters.shape[0]): * cluster_id = empty_clusters[i] # <<<<<<<<<<<<<< @@ -4686,23 +5941,20 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } else if (unlikely(__pyx_t_19 >= __pyx_pybuffernd_empty_clusters.diminfo[0].shape)) __pyx_t_13 = 0; if (unlikely(__pyx_t_13 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v_cluster_id = (*__Pyx_BufPtrCContig1d(npy_intp *, __pyx_pybuffernd_empty_clusters.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_empty_clusters.diminfo[0].strides)); - /* "sklearn/cluster/_k_means.pyx":348 + /* "sklearn/cluster/_k_means.pyx":434 * * # XXX two relocated clusters could be close to each other * centers[cluster_id] = 0. # <<<<<<<<<<<<<< * add_row_csr(data, indices, indptr, far_from_centers[i], * centers[cluster_id]) */ - __pyx_t_6 = PyFloat_FromDouble(0.); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, __pyx_t_6, sizeof(npy_intp), __Pyx_PyInt_to_py_Py_intptr_t, 0, 1, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, __pyx_float_0_, npy_intp, 1, __Pyx_PyInt_From_Py_intptr_t, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/cluster/_k_means.pyx":349 + /* "sklearn/cluster/_k_means.pyx":435 * # XXX two relocated clusters could be close to each other * centers[cluster_id] = 0. * add_row_csr(data, indices, indptr, far_from_centers[i], # <<<<<<<<<<<<<< @@ -4717,23 +5969,31 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } else if (unlikely(__pyx_t_20 >= __pyx_pybuffernd_far_from_centers.diminfo[0].shape)) __pyx_t_13 = 0; if (unlikely(__pyx_t_13 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "sklearn/cluster/_k_means.pyx":350 + /* "sklearn/cluster/_k_means.pyx":436 * centers[cluster_id] = 0. * add_row_csr(data, indices, indptr, far_from_centers[i], * centers[cluster_id]) # <<<<<<<<<<<<<< * n_samples_in_cluster[cluster_id] = 1 * */ - __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, sizeof(npy_intp), __Pyx_PyInt_to_py_Py_intptr_t, 0, 1, 1); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_v_cluster_id, npy_intp, 1, __Pyx_PyInt_From_Py_intptr_t, 0, 1, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_6); - if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "sklearn/cluster/_k_means.pyx":435 + * # XXX two relocated clusters could be close to each other + * centers[cluster_id] = 0. + * add_row_csr(data, indices, indptr, far_from_centers[i], # <<<<<<<<<<<<<< + * centers[cluster_id]) + * n_samples_in_cluster[cluster_id] = 1 + */ __pyx_f_7sklearn_5utils_11sparsefuncs_add_row_csr(((PyArrayObject *)__pyx_v_data), ((PyArrayObject *)__pyx_v_indices), ((PyArrayObject *)__pyx_v_indptr), (*__Pyx_BufPtrStrided1d(npy_intp *, __pyx_pybuffernd_far_from_centers.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_far_from_centers.diminfo[0].strides)), ((PyArrayObject *)__pyx_t_6)); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "sklearn/cluster/_k_means.pyx":351 + /* "sklearn/cluster/_k_means.pyx":437 * add_row_csr(data, indices, indptr, far_from_centers[i], * centers[cluster_id]) * n_samples_in_cluster[cluster_id] = 1 # <<<<<<<<<<<<<< @@ -4748,12 +6008,12 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } else if (unlikely(__pyx_t_21 >= __pyx_pybuffernd_n_samples_in_cluster.diminfo[0].shape)) __pyx_t_13 = 0; if (unlikely(__pyx_t_13 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } *__Pyx_BufPtrCContig1d(npy_intp *, __pyx_pybuffernd_n_samples_in_cluster.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_n_samples_in_cluster.diminfo[0].strides) = 1; } - /* "sklearn/cluster/_k_means.pyx":353 + /* "sklearn/cluster/_k_means.pyx":439 * n_samples_in_cluster[cluster_id] = 1 * * for i in range(labels.shape[0]): # <<<<<<<<<<<<<< @@ -4764,12 +6024,12 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) { __pyx_v_i = __pyx_t_18; - /* "sklearn/cluster/_k_means.pyx":354 + /* "sklearn/cluster/_k_means.pyx":440 * * for i in range(labels.shape[0]): * add_row_csr(data, indices, indptr, i, centers[labels[i]]) # <<<<<<<<<<<<<< * - * centers /= n_samples_in_cluster[:, np.newaxis] + * # todo center computation needs to be aware of the distance measure */ __pyx_t_22 = __pyx_v_i; __pyx_t_13 = -1; @@ -4779,43 +6039,43 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } else if (unlikely(__pyx_t_22 >= __pyx_pybuffernd_labels.diminfo[0].shape)) __pyx_t_13 = 0; if (unlikely(__pyx_t_13 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_23 = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_7cluster_8_k_means_INT *, __pyx_pybuffernd_labels.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_labels.diminfo[0].strides)); - __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_23, sizeof(__pyx_t_7sklearn_7cluster_8_k_means_INT), __Pyx_PyInt_to_py_npy_int32, 0, 1, 1); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_centers), __pyx_t_23, __pyx_t_7sklearn_7cluster_8_k_means_INT, 1, __Pyx_PyInt_From_npy_int32, 0, 1, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_6); - if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_f_7sklearn_5utils_11sparsefuncs_add_row_csr(((PyArrayObject *)__pyx_v_data), ((PyArrayObject *)__pyx_v_indices), ((PyArrayObject *)__pyx_v_indptr), __pyx_v_i, ((PyArrayObject *)__pyx_t_6)); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } - /* "sklearn/cluster/_k_means.pyx":356 - * add_row_csr(data, indices, indptr, i, centers[labels[i]]) + /* "sklearn/cluster/_k_means.pyx":443 * + * # todo center computation needs to be aware of the distance measure * centers /= n_samples_in_cluster[:, np.newaxis] # <<<<<<<<<<<<<< * * return centers */ - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s__newaxis); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_newaxis); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __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 = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_k_slice_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_k_slice_6); - __Pyx_GIVEREF(__pyx_k_slice_6); + __Pyx_INCREF(__pyx_slice__5); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_slice__5); + __Pyx_GIVEREF(__pyx_slice__5); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_GetItem(((PyObject *)__pyx_v_n_samples_in_cluster), ((PyObject *)__pyx_t_6)); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_GetItem(((PyObject *)__pyx_v_n_samples_in_cluster), __pyx_t_6); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_centers), __pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyNumber_InPlaceDivide(((PyObject *)__pyx_v_centers), __pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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 = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; @@ -4831,14 +6091,13 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN } } __pyx_pybuffernd_centers.diminfo[0].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_centers.diminfo[0].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_centers.diminfo[1].strides = __pyx_pybuffernd_centers.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_centers.diminfo[1].shape = __pyx_pybuffernd_centers.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_centers)); - __pyx_v_centers = ((PyArrayObject *)__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_centers, ((PyArrayObject *)__pyx_t_6)); __pyx_t_6 = 0; - /* "sklearn/cluster/_k_means.pyx":358 + /* "sklearn/cluster/_k_means.pyx":445 * centers /= n_samples_in_cluster[:, np.newaxis] * * return centers # <<<<<<<<<<<<<< @@ -4848,8 +6107,15 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN __pyx_r = ((PyObject *)__pyx_v_centers); goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "sklearn/cluster/_k_means.pyx":384 + * + * + * def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, # <<<<<<<<<<<<<< + * np.ndarray[DOUBLE, ndim=1] distances): + * """M step of the K-means EM algorithm + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); @@ -4895,6 +6161,14 @@ static PyObject *__pyx_pf_7sklearn_7cluster_8_k_means_8_centers_sparse(CYTHON_UN return __pyx_r; } +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":194 + * # experimental exception made for __getbuffer__ and __releasebuffer__ + * # -- the details of this may change. + * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fullfill the PEP. + */ + /* Python wrapper */ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { @@ -4902,18 +6176,12 @@ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "numpy.pxd":194 - * # experimental exception made for __getbuffer__ and __releasebuffer__ - * # -- the details of this may change. - * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fullfill the PEP. - */ - static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { int __pyx_v_copy_shape; int __pyx_v_i; @@ -4947,7 +6215,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 194); - /* "numpy.pxd":200 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":200 * # of flags * * if info == NULL: return # <<<<<<<<<<<<<< @@ -4958,11 +6226,9 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P if (__pyx_t_1) { __pyx_r = 0; goto __pyx_L0; - goto __pyx_L3; } - __pyx_L3:; - /* "numpy.pxd":203 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":203 * * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -4971,7 +6237,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_endian_detector = 1; - /* "numpy.pxd":204 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":204 * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -4980,7 +6246,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "numpy.pxd":206 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":206 * cdef bint little_endian = ((&endian_detector)[0] != 0) * * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< @@ -4989,7 +6255,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_ndim = PyArray_NDIM(__pyx_v_self); - /* "numpy.pxd":208 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":208 * ndim = PyArray_NDIM(self) * * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< @@ -4999,7 +6265,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0); if (__pyx_t_1) { - /* "numpy.pxd":209 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":209 * * if sizeof(npy_intp) != sizeof(Py_ssize_t): * copy_shape = 1 # <<<<<<<<<<<<<< @@ -5011,7 +6277,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":211 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":211 * copy_shape = 1 * else: * copy_shape = 0 # <<<<<<<<<<<<<< @@ -5022,7 +6288,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L4:; - /* "numpy.pxd":213 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":213 * copy_shape = 0 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< @@ -5032,7 +6298,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_1 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0); if (__pyx_t_1) { - /* "numpy.pxd":214 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":214 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< @@ -5046,23 +6312,21 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (__pyx_t_3) { - /* "numpy.pxd":215 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":215 * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; } - __pyx_L5:; - /* "numpy.pxd":217 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":217 * raise ValueError(u"ndarray is not C contiguous") * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< @@ -5072,7 +6336,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_3 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0); if (__pyx_t_3) { - /* "numpy.pxd":218 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":218 * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< @@ -5086,23 +6350,21 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (__pyx_t_2) { - /* "numpy.pxd":219 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":219 * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< * * info.buf = PyArray_DATA(self) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; } - __pyx_L6:; - /* "numpy.pxd":221 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":221 * raise ValueError(u"ndarray is not Fortran contiguous") * * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< @@ -5111,7 +6373,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->buf = PyArray_DATA(__pyx_v_self); - /* "numpy.pxd":222 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":222 * * info.buf = PyArray_DATA(self) * info.ndim = ndim # <<<<<<<<<<<<<< @@ -5120,7 +6382,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->ndim = __pyx_v_ndim; - /* "numpy.pxd":223 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":223 * info.buf = PyArray_DATA(self) * info.ndim = ndim * if copy_shape: # <<<<<<<<<<<<<< @@ -5130,7 +6392,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_2 = (__pyx_v_copy_shape != 0); if (__pyx_t_2) { - /* "numpy.pxd":226 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":226 * # Allocate new buffer for strides and shape info. * # This is allocated as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< @@ -5139,7 +6401,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2))); - /* "numpy.pxd":227 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":227 * # This is allocated as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim # <<<<<<<<<<<<<< @@ -5148,7 +6410,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); - /* "numpy.pxd":228 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":228 * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim * for i in range(ndim): # <<<<<<<<<<<<<< @@ -5159,7 +6421,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "numpy.pxd":229 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":229 * info.shape = info.strides + ndim * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< @@ -5168,7 +6430,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]); - /* "numpy.pxd":230 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":230 * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< @@ -5181,7 +6443,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":232 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":232 * info.shape[i] = PyArray_DIMS(self)[i] * else: * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< @@ -5190,7 +6452,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self)); - /* "numpy.pxd":233 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":233 * else: * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< @@ -5201,7 +6463,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L7:; - /* "numpy.pxd":234 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":234 * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL # <<<<<<<<<<<<<< @@ -5210,7 +6472,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->suboffsets = NULL; - /* "numpy.pxd":235 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":235 * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< @@ -5219,7 +6481,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self); - /* "numpy.pxd":236 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":236 * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< @@ -5228,7 +6490,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0)); - /* "numpy.pxd":239 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":239 * * cdef int t * cdef char* f = NULL # <<<<<<<<<<<<<< @@ -5237,7 +6499,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_f = NULL; - /* "numpy.pxd":240 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":240 * cdef int t * cdef char* f = NULL * cdef dtype descr = self.descr # <<<<<<<<<<<<<< @@ -5249,7 +6511,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_v_descr = ((PyArray_Descr *)__pyx_t_4); __pyx_t_4 = 0; - /* "numpy.pxd":244 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":244 * cdef int offset * * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< @@ -5258,7 +6520,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); - /* "numpy.pxd":246 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":246 * cdef bint hasfields = PyDataType_HASFIELDS(descr) * * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< @@ -5274,7 +6536,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (__pyx_t_1) { - /* "numpy.pxd":248 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":248 * if not hasfields and not copy_shape: * # do not call releasebuffer * info.obj = None # <<<<<<<<<<<<<< @@ -5290,7 +6552,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":251 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":251 * else: * # need to call releasebuffer * info.obj = self # <<<<<<<<<<<<<< @@ -5305,7 +6567,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L10:; - /* "numpy.pxd":253 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":253 * info.obj = self * * if not hasfields: # <<<<<<<<<<<<<< @@ -5315,7 +6577,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_1 = ((!(__pyx_v_hasfields != 0)) != 0); if (__pyx_t_1) { - /* "numpy.pxd":254 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":254 * * if not hasfields: * t = descr.type_num # <<<<<<<<<<<<<< @@ -5325,7 +6587,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_5 = __pyx_v_descr->type_num; __pyx_v_t = __pyx_t_5; - /* "numpy.pxd":255 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":255 * if not hasfields: * t = descr.type_num * if ((descr.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< @@ -5340,7 +6602,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (!__pyx_t_2) { - /* "numpy.pxd":256 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":256 * t = descr.type_num * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< @@ -5360,23 +6622,21 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (__pyx_t_1) { - /* "numpy.pxd":257 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257 * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; } - __pyx_L12:; - /* "numpy.pxd":274 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":274 * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< @@ -5385,7 +6645,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ switch (__pyx_v_t) { - /* "numpy.pxd":258 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":258 * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< @@ -5393,10 +6653,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_SHORT: f = "h" */ case NPY_BYTE: - __pyx_v_f = __pyx_k__b; + __pyx_v_f = __pyx_k_b; break; - /* "numpy.pxd":259 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":259 * raise ValueError(u"Non-native byte order not supported") * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< @@ -5404,10 +6664,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_USHORT: f = "H" */ case NPY_UBYTE: - __pyx_v_f = __pyx_k__B; + __pyx_v_f = __pyx_k_B; break; - /* "numpy.pxd":260 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":260 * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< @@ -5415,10 +6675,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_INT: f = "i" */ case NPY_SHORT: - __pyx_v_f = __pyx_k__h; + __pyx_v_f = __pyx_k_h; break; - /* "numpy.pxd":261 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":261 * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< @@ -5426,10 +6686,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_UINT: f = "I" */ case NPY_USHORT: - __pyx_v_f = __pyx_k__H; + __pyx_v_f = __pyx_k_H; break; - /* "numpy.pxd":262 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":262 * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< @@ -5437,10 +6697,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONG: f = "l" */ case NPY_INT: - __pyx_v_f = __pyx_k__i; + __pyx_v_f = __pyx_k_i; break; - /* "numpy.pxd":263 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":263 * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< @@ -5448,10 +6708,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_ULONG: f = "L" */ case NPY_UINT: - __pyx_v_f = __pyx_k__I; + __pyx_v_f = __pyx_k_I; break; - /* "numpy.pxd":264 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":264 * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< @@ -5459,10 +6719,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONGLONG: f = "q" */ case NPY_LONG: - __pyx_v_f = __pyx_k__l; + __pyx_v_f = __pyx_k_l; break; - /* "numpy.pxd":265 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":265 * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< @@ -5470,10 +6730,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_ULONGLONG: f = "Q" */ case NPY_ULONG: - __pyx_v_f = __pyx_k__L; + __pyx_v_f = __pyx_k_L; break; - /* "numpy.pxd":266 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":266 * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< @@ -5481,10 +6741,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_FLOAT: f = "f" */ case NPY_LONGLONG: - __pyx_v_f = __pyx_k__q; + __pyx_v_f = __pyx_k_q; break; - /* "numpy.pxd":267 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":267 * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< @@ -5492,10 +6752,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_DOUBLE: f = "d" */ case NPY_ULONGLONG: - __pyx_v_f = __pyx_k__Q; + __pyx_v_f = __pyx_k_Q; break; - /* "numpy.pxd":268 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":268 * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< @@ -5503,10 +6763,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONGDOUBLE: f = "g" */ case NPY_FLOAT: - __pyx_v_f = __pyx_k__f; + __pyx_v_f = __pyx_k_f; break; - /* "numpy.pxd":269 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":269 * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< @@ -5514,10 +6774,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CFLOAT: f = "Zf" */ case NPY_DOUBLE: - __pyx_v_f = __pyx_k__d; + __pyx_v_f = __pyx_k_d; break; - /* "numpy.pxd":270 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":270 * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< @@ -5525,10 +6785,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CDOUBLE: f = "Zd" */ case NPY_LONGDOUBLE: - __pyx_v_f = __pyx_k__g; + __pyx_v_f = __pyx_k_g; break; - /* "numpy.pxd":271 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":271 * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< @@ -5536,10 +6796,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CLONGDOUBLE: f = "Zg" */ case NPY_CFLOAT: - __pyx_v_f = __pyx_k__Zf; + __pyx_v_f = __pyx_k_Zf; break; - /* "numpy.pxd":272 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":272 * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< @@ -5547,10 +6807,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_OBJECT: f = "O" */ case NPY_CDOUBLE: - __pyx_v_f = __pyx_k__Zd; + __pyx_v_f = __pyx_k_Zd; break; - /* "numpy.pxd":273 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":273 * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< @@ -5558,10 +6818,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * else: */ case NPY_CLONGDOUBLE: - __pyx_v_f = __pyx_k__Zg; + __pyx_v_f = __pyx_k_Zg; break; - /* "numpy.pxd":274 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":274 * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< @@ -5569,37 +6829,37 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) */ case NPY_OBJECT: - __pyx_v_f = __pyx_k__O; + __pyx_v_f = __pyx_k_O; break; default: - /* "numpy.pxd":276 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":276 * elif t == NPY_OBJECT: f = "O" * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * info.format = f * return */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_13), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __pyx_t_8 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_8)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } - /* "numpy.pxd":277 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":277 * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * info.format = f # <<<<<<<<<<<<<< @@ -5608,7 +6868,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->format = __pyx_v_f; - /* "numpy.pxd":278 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":278 * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * info.format = f * return # <<<<<<<<<<<<<< @@ -5617,11 +6877,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_r = 0; goto __pyx_L0; - goto __pyx_L11; } /*else*/ { - /* "numpy.pxd":280 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":280 * return * else: * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< @@ -5630,7 +6889,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->format = ((char *)malloc(255)); - /* "numpy.pxd":281 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":281 * else: * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = c'^' # Native data types, manual alignment # <<<<<<<<<<<<<< @@ -5639,7 +6898,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_info->format[0]) = '^'; - /* "numpy.pxd":282 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":282 * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = c'^' # Native data types, manual alignment * offset = 0 # <<<<<<<<<<<<<< @@ -5648,17 +6907,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_offset = 0; - /* "numpy.pxd":285 - * f = _util_dtypestring(descr, info.format + 1, + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":283 + * info.format[0] = c'^' # Native data types, manual alignment + * offset = 0 + * f = _util_dtypestring(descr, info.format + 1, # <<<<<<<<<<<<<< * info.format + _buffer_format_string_len, - * &offset) # <<<<<<<<<<<<<< - * f[0] = c'\0' # Terminate format string - * + * &offset) */ __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_f = __pyx_t_9; - /* "numpy.pxd":286 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":286 * info.format + _buffer_format_string_len, * &offset) * f[0] = c'\0' # Terminate format string # <<<<<<<<<<<<<< @@ -5667,8 +6926,16 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_f[0]) = '\x00'; } - __pyx_L11:; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":194 + * # experimental exception made for __getbuffer__ and __releasebuffer__ + * # -- the details of this may change. + * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fullfill the PEP. + */ + + /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; @@ -5693,23 +6960,25 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P return __pyx_r; } +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":288 + * f[0] = c'\0' # Terminate format string + * + * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + */ + /* Python wrapper */ static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); + + /* function exit code */ __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":288 - * f[0] = c'\0' # Terminate format string - * - * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - */ - static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -5717,7 +6986,7 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s __Pyx_RefNannySetupContext("__releasebuffer__", 0); __Pyx_TraceCall("__releasebuffer__", __pyx_f[1], 288); - /* "numpy.pxd":289 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":289 * * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< @@ -5727,7 +6996,7 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0); if (__pyx_t_1) { - /* "numpy.pxd":290 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":290 * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): * stdlib.free(info.format) # <<<<<<<<<<<<<< @@ -5739,7 +7008,7 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s } __pyx_L3:; - /* "numpy.pxd":291 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":291 * if PyArray_HASFIELDS(self): * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< @@ -5749,7 +7018,7 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0); if (__pyx_t_1) { - /* "numpy.pxd":292 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":292 * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): * stdlib.free(info.strides) # <<<<<<<<<<<<<< @@ -5761,11 +7030,20 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s } __pyx_L4:; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":288 + * f[0] = c'\0' # Terminate format string + * + * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + */ + + /* function exit code */ __Pyx_TraceReturn(Py_None); __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":768 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":768 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -5784,7 +7062,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); __Pyx_TraceCall("PyArray_MultiIterNew1", __pyx_f[1], 768); - /* "numpy.pxd":769 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":769 * * cdef inline object PyArray_MultiIterNew1(a): * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< @@ -5798,8 +7076,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":768 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, a) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5811,7 +7096,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ return __pyx_r; } -/* "numpy.pxd":771 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":771 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -5830,7 +7115,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); __Pyx_TraceCall("PyArray_MultiIterNew2", __pyx_f[1], 771); - /* "numpy.pxd":772 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":772 * * cdef inline object PyArray_MultiIterNew2(a, b): * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< @@ -5844,8 +7129,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":771 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, b) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5857,7 +7149,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ return __pyx_r; } -/* "numpy.pxd":774 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":774 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -5876,7 +7168,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); __Pyx_TraceCall("PyArray_MultiIterNew3", __pyx_f[1], 774); - /* "numpy.pxd":775 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":775 * * cdef inline object PyArray_MultiIterNew3(a, b, c): * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< @@ -5890,8 +7182,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":774 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, c) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5903,7 +7202,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ return __pyx_r; } -/* "numpy.pxd":777 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":777 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -5922,7 +7221,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); __Pyx_TraceCall("PyArray_MultiIterNew4", __pyx_f[1], 777); - /* "numpy.pxd":778 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":778 * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< @@ -5936,8 +7235,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":777 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, d) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5949,7 +7255,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ return __pyx_r; } -/* "numpy.pxd":780 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":780 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -5968,7 +7274,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); __Pyx_TraceCall("PyArray_MultiIterNew5", __pyx_f[1], 780); - /* "numpy.pxd":781 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":781 * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< @@ -5982,8 +7288,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":780 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5995,7 +7308,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ return __pyx_r; } -/* "numpy.pxd":783 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":783 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< @@ -6017,14 +7330,13 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx Py_ssize_t __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_5; + int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; int __pyx_t_9; - int __pyx_t_10; - long __pyx_t_11; - char *__pyx_t_12; + long __pyx_t_10; + char *__pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -6032,7 +7344,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx __Pyx_RefNannySetupContext("_util_dtypestring", 0); __Pyx_TraceCall("_util_dtypestring", __pyx_f[1], 783); - /* "numpy.pxd":790 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":790 * cdef int delta_offset * cdef tuple i * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -6041,7 +7353,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_endian_detector = 1; - /* "numpy.pxd":791 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":791 * cdef tuple i * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -6050,18 +7362,18 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "numpy.pxd":794 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":794 * cdef tuple fields * * for childname in descr.names: # <<<<<<<<<<<<<< * fields = descr.fields[childname] * child, new_offset = fields */ - if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) { + if (unlikely(__pyx_v_descr->names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; for (;;) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON @@ -6069,33 +7381,31 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx #else __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif - __Pyx_XDECREF(__pyx_v_childname); - __pyx_v_childname = __pyx_t_3; + __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3); __pyx_t_3 = 0; - /* "numpy.pxd":795 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":795 * * for childname in descr.names: * fields = descr.fields[childname] # <<<<<<<<<<<<<< * child, new_offset = fields * */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_3); - if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_fields)); - __pyx_v_fields = ((PyObject*)__pyx_t_3); + if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; - /* "numpy.pxd":796 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":796 * for childname in descr.names: * fields = descr.fields[childname] * child, new_offset = fields # <<<<<<<<<<<<<< * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: */ - if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) { - PyObject* sequence = ((PyObject *)__pyx_v_fields); + if (likely(__pyx_v_fields != Py_None)) { + PyObject* sequence = __pyx_v_fields; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else @@ -6117,129 +7427,96 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); #endif - } else if (1) { + } else { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else - { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_fields)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; } if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_child)); - __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_new_offset); - __pyx_v_new_offset = __pyx_t_4; + __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4); __pyx_t_4 = 0; - /* "numpy.pxd":798 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":798 * child, new_offset = fields * - * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< + * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") * */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __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_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":799 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799 * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< * * if ((child.byteorder == c'>' and little_endian) or */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; } - __pyx_L7:; - /* "numpy.pxd":801 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":801 * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") * * if ((child.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") */ - __pyx_t_7 = ((__pyx_v_child->byteorder == '>') != 0); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_little_endian != 0); + __pyx_t_6 = ((__pyx_v_child->byteorder == '>') != 0); + if (__pyx_t_6) { + __pyx_t_7 = (__pyx_v_little_endian != 0); } else { - __pyx_t_8 = __pyx_t_7; + __pyx_t_7 = __pyx_t_6; } - if (!__pyx_t_8) { + if (!__pyx_t_7) { - /* "numpy.pxd":802 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":802 * * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< * raise ValueError(u"Non-native byte order not supported") * # One could encode it in the format string and have Cython */ - __pyx_t_7 = ((__pyx_v_child->byteorder == '<') != 0); - if (__pyx_t_7) { - __pyx_t_9 = ((!(__pyx_v_little_endian != 0)) != 0); - __pyx_t_10 = __pyx_t_9; + __pyx_t_6 = ((__pyx_v_child->byteorder == '<') != 0); + if (__pyx_t_6) { + __pyx_t_8 = ((!(__pyx_v_little_endian != 0)) != 0); + __pyx_t_9 = __pyx_t_8; } else { - __pyx_t_10 = __pyx_t_7; + __pyx_t_9 = __pyx_t_6; } - __pyx_t_7 = __pyx_t_10; + __pyx_t_6 = __pyx_t_9; } else { - __pyx_t_7 = __pyx_t_8; + __pyx_t_6 = __pyx_t_7; } - if (__pyx_t_7) { + if (__pyx_t_6) { - /* "numpy.pxd":803 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803 * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * # One could encode it in the format string and have Cython * # complain instead, BUT: < and > in format strings also imply */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; } - __pyx_L8:; - /* "numpy.pxd":813 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":813 * * # Output padding bytes * while offset[0] < new_offset: # <<<<<<<<<<<<<< @@ -6247,15 +7524,15 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx * f += 1 */ while (1) { - __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_7) break; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_6) break; - /* "numpy.pxd":814 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":814 * # Output padding bytes * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< @@ -6264,7 +7541,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ (__pyx_v_f[0]) = 120; - /* "numpy.pxd":815 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":815 * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte * f += 1 # <<<<<<<<<<<<<< @@ -6273,413 +7550,410 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_f = (__pyx_v_f + 1); - /* "numpy.pxd":816 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":816 * f[0] = 120 # "x"; pad byte * f += 1 * offset[0] += 1 # <<<<<<<<<<<<<< * * offset[0] += child.itemsize */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + 1); + __pyx_t_10 = 0; + (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + 1); } - /* "numpy.pxd":818 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":818 * offset[0] += 1 * * offset[0] += child.itemsize # <<<<<<<<<<<<<< * * if not PyDataType_HASFIELDS(child): */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + __pyx_v_child->elsize); + __pyx_t_10 = 0; + (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + __pyx_v_child->elsize); - /* "numpy.pxd":820 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":820 * offset[0] += child.itemsize * * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< * t = child.type_num * if end - f < 5: */ - __pyx_t_7 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0); - if (__pyx_t_7) { + __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":821 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":821 * * if not PyDataType_HASFIELDS(child): * t = child.type_num # <<<<<<<<<<<<<< * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_t); - __pyx_v_t = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4); + __pyx_t_4 = 0; - /* "numpy.pxd":822 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":822 * if not PyDataType_HASFIELDS(child): * t = child.type_num * if end - f < 5: # <<<<<<<<<<<<<< * raise RuntimeError(u"Format string allocated too short.") * */ - __pyx_t_7 = (((__pyx_v_end - __pyx_v_f) < 5) != 0); - if (__pyx_t_7) { + __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":823 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823 * t = child.type_num * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< * * # Until ticket #99 is fixed, use integers to avoid warnings */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; } - __pyx_L12:; - /* "numpy.pxd":826 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":826 * * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" */ - __pyx_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 98; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":827 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":827 * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" */ - __pyx_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 66; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":828 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":828 * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" */ - __pyx_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 104; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":829 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":829 * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" */ - __pyx_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 72; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":830 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":830 * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" */ - __pyx_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 105; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":831 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":831 * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" */ - __pyx_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 73; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":832 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":832 * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" */ - __pyx_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 108; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":833 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":833 * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 76; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":834 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":834 * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 113; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":835 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":835 * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 81; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":836 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":836 * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" */ - __pyx_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 102; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":837 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":837 * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf */ - __pyx_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 100; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":838 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":838 * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 103; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":839 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":839 * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg */ - __pyx_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 102; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":840 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":840 * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" */ - __pyx_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 100; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":841 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":841 * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: */ - __pyx_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 103; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":842 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":842 * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) */ - __pyx_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 79; - goto __pyx_L13; + goto __pyx_L11; } /*else*/ { - /* "numpy.pxd":844 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":844 * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * f += 1 * else: */ - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_13), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L13:; + __pyx_L11:; - /* "numpy.pxd":845 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":845 * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * f += 1 # <<<<<<<<<<<<<< @@ -6687,25 +7961,25 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx * # Cython ignores struct boundary information ("T{...}"), */ __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L11; + goto __pyx_L9; } /*else*/ { - /* "numpy.pxd":849 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":849 * # Cython ignores struct boundary information ("T{...}"), * # so don't output it * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< * return f * */ - __pyx_t_12 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_12; + __pyx_t_11 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_11; } - __pyx_L11:; + __pyx_L9:; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "numpy.pxd":850 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":850 * # so don't output it * f = _util_dtypestring(child, f, end, offset) * return f # <<<<<<<<<<<<<< @@ -6715,13 +7989,19 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx __pyx_r = __pyx_v_f; goto __pyx_L0; - __pyx_r = 0; - goto __pyx_L0; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":783 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< + * # Recursive utility function used in __getbuffer__ to get format + * # string. The new location in the format string is returned. + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -6735,7 +8015,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx return __pyx_r; } -/* "numpy.pxd":965 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":966 * * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -6750,9 +8030,9 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a int __pyx_t_2; __Pyx_TraceDeclarations __Pyx_RefNannySetupContext("set_array_base", 0); - __Pyx_TraceCall("set_array_base", __pyx_f[1], 965); + __Pyx_TraceCall("set_array_base", __pyx_f[1], 966); - /* "numpy.pxd":967 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":968 * cdef inline void set_array_base(ndarray arr, object base): * cdef PyObject* baseptr * if base is None: # <<<<<<<<<<<<<< @@ -6763,7 +8043,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "numpy.pxd":968 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":969 * cdef PyObject* baseptr * if base is None: * baseptr = NULL # <<<<<<<<<<<<<< @@ -6775,7 +8055,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a } /*else*/ { - /* "numpy.pxd":970 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":971 * baseptr = NULL * else: * Py_INCREF(base) # important to do this before decref below! # <<<<<<<<<<<<<< @@ -6784,7 +8064,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_INCREF(__pyx_v_base); - /* "numpy.pxd":971 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":972 * else: * Py_INCREF(base) # important to do this before decref below! * baseptr = base # <<<<<<<<<<<<<< @@ -6795,7 +8075,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a } __pyx_L3:; - /* "numpy.pxd":972 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":973 * Py_INCREF(base) # important to do this before decref below! * baseptr = base * Py_XDECREF(arr.base) # <<<<<<<<<<<<<< @@ -6804,7 +8084,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_XDECREF(__pyx_v_arr->base); - /* "numpy.pxd":973 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":974 * baseptr = base * Py_XDECREF(arr.base) * arr.base = baseptr # <<<<<<<<<<<<<< @@ -6813,11 +8093,20 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ __pyx_v_arr->base = __pyx_v_baseptr; + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":966 + * + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * cdef PyObject* baseptr + * if base is None: + */ + + /* function exit code */ __Pyx_TraceReturn(Py_None); __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":975 +/* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":976 * arr.base = baseptr * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -6831,9 +8120,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py int __pyx_t_1; __Pyx_TraceDeclarations __Pyx_RefNannySetupContext("get_array_base", 0); - __Pyx_TraceCall("get_array_base", __pyx_f[1], 975); + __Pyx_TraceCall("get_array_base", __pyx_f[1], 976); - /* "numpy.pxd":976 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":977 * * cdef inline object get_array_base(ndarray arr): * if arr.base is NULL: # <<<<<<<<<<<<<< @@ -6843,7 +8132,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0); if (__pyx_t_1) { - /* "numpy.pxd":977 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":978 * cdef inline object get_array_base(ndarray arr): * if arr.base is NULL: * return None # <<<<<<<<<<<<<< @@ -6854,11 +8143,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __Pyx_INCREF(Py_None); __pyx_r = Py_None; goto __pyx_L0; - goto __pyx_L3; } /*else*/ { - /* "numpy.pxd":979 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":980 * return None * else: * return arr.base # <<<<<<<<<<<<<< @@ -6868,9 +8156,16 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_r = ((PyObject *)__pyx_v_arr->base); goto __pyx_L0; } - __pyx_L3:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":976 + * arr.base = baseptr + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * if arr.base is NULL: + * return None + */ + + /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r); @@ -6879,8 +8174,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py } static PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("_assign_labels_array"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means__assign_labels_array)}, - {__Pyx_NAMESTR("_assign_labels_csr"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_2_assign_labels_csr)}, + {__Pyx_NAMESTR("_assign_labels_array_L1"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_1_assign_labels_array_L1, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means__assign_labels_array_L1)}, + {__Pyx_NAMESTR("_assign_labels_csr_L1"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_3_assign_labels_csr_L1, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_2_assign_labels_csr_L1)}, + {__Pyx_NAMESTR("_assign_labels_array"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_5_assign_labels_array, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_4_assign_labels_array)}, + {__Pyx_NAMESTR("_assign_labels_csr"), (PyCFunction)__pyx_pw_7sklearn_7cluster_8_k_means_7_assign_labels_csr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_7cluster_8_k_means_6_assign_labels_csr)}, {0, 0, 0, 0} }; @@ -6903,84 +8200,86 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_n_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 1}, - {&__pyx_kp_u_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 1, 0, 0}, - {&__pyx_kp_u_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 1, 0, 0}, - {&__pyx_kp_u_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 1, 0, 0}, - {&__pyx_kp_u_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 1, 0, 0}, - {&__pyx_n_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 1}, - {&__pyx_n_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 1}, - {&__pyx_n_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 1}, - {&__pyx_n_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 1}, - {&__pyx_n_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 1}, - {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0}, - {&__pyx_n_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 1}, - {&__pyx_n_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 1}, - {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0}, - {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0}, - {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s__X, __pyx_k__X, sizeof(__pyx_k__X), 0, 0, 1, 1}, - {&__pyx_n_s__X_data, __pyx_k__X_data, sizeof(__pyx_k__X_data), 0, 0, 1, 1}, - {&__pyx_n_s__X_indices, __pyx_k__X_indices, sizeof(__pyx_k__X_indices), 0, 0, 1, 1}, - {&__pyx_n_s__X_indptr, __pyx_k__X_indptr, sizeof(__pyx_k__X_indptr), 0, 0, 1, 1}, - {&__pyx_n_s____import__, __pyx_k____import__, sizeof(__pyx_k____import__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____pyx_getbuffer, __pyx_k____pyx_getbuffer, sizeof(__pyx_k____pyx_getbuffer), 0, 0, 1, 1}, - {&__pyx_n_s____pyx_releasebuffer, __pyx_k____pyx_releasebuffer, sizeof(__pyx_k____pyx_releasebuffer), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s___centers_dense, __pyx_k___centers_dense, sizeof(__pyx_k___centers_dense), 0, 0, 1, 1}, - {&__pyx_n_s___centers_sparse, __pyx_k___centers_sparse, sizeof(__pyx_k___centers_sparse), 0, 0, 1, 1}, - {&__pyx_n_s__argsort, __pyx_k__argsort, sizeof(__pyx_k__argsort), 0, 0, 1, 1}, - {&__pyx_n_s__bincount, __pyx_k__bincount, sizeof(__pyx_k__bincount), 0, 0, 1, 1}, - {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1}, - {&__pyx_n_s__center_diff, __pyx_k__center_diff, sizeof(__pyx_k__center_diff), 0, 0, 1, 1}, - {&__pyx_n_s__center_idx, __pyx_k__center_idx, sizeof(__pyx_k__center_idx), 0, 0, 1, 1}, - {&__pyx_n_s__centers, __pyx_k__centers, sizeof(__pyx_k__centers), 0, 0, 1, 1}, - {&__pyx_n_s__cluster_id, __pyx_k__cluster_id, sizeof(__pyx_k__cluster_id), 0, 0, 1, 1}, - {&__pyx_n_s__counts, __pyx_k__counts, sizeof(__pyx_k__counts), 0, 0, 1, 1}, - {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1}, - {&__pyx_n_s__distances, __pyx_k__distances, sizeof(__pyx_k__distances), 0, 0, 1, 1}, - {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, - {&__pyx_n_s__empty_clusters, __pyx_k__empty_clusters, sizeof(__pyx_k__empty_clusters), 0, 0, 1, 1}, - {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, - {&__pyx_n_s__far_from_centers, __pyx_k__far_from_centers, sizeof(__pyx_k__far_from_centers), 0, 0, 1, 1}, - {&__pyx_n_s__feature_idx, __pyx_k__feature_idx, sizeof(__pyx_k__feature_idx), 0, 0, 1, 1}, - {&__pyx_n_s__float64, __pyx_k__float64, sizeof(__pyx_k__float64), 0, 0, 1, 1}, - {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, - {&__pyx_n_s__indices, __pyx_k__indices, sizeof(__pyx_k__indices), 0, 0, 1, 1}, - {&__pyx_n_s__indptr, __pyx_k__indptr, sizeof(__pyx_k__indptr), 0, 0, 1, 1}, - {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, - {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, - {&__pyx_n_s__labels, __pyx_k__labels, sizeof(__pyx_k__labels), 0, 0, 1, 1}, - {&__pyx_n_s__minlength, __pyx_k__minlength, sizeof(__pyx_k__minlength), 0, 0, 1, 1}, - {&__pyx_n_s__n_clusters, __pyx_k__n_clusters, sizeof(__pyx_k__n_clusters), 0, 0, 1, 1}, - {&__pyx_n_s__n_features, __pyx_k__n_features, sizeof(__pyx_k__n_features), 0, 0, 1, 1}, - {&__pyx_n_s__n_samples, __pyx_k__n_samples, sizeof(__pyx_k__n_samples), 0, 0, 1, 1}, - {&__pyx_n_s__nearest_center, __pyx_k__nearest_center, sizeof(__pyx_k__nearest_center), 0, 0, 1, 1}, - {&__pyx_n_s__new_center, __pyx_k__new_center, sizeof(__pyx_k__new_center), 0, 0, 1, 1}, - {&__pyx_n_s__new_count, __pyx_k__new_count, sizeof(__pyx_k__new_count), 0, 0, 1, 1}, - {&__pyx_n_s__newaxis, __pyx_k__newaxis, sizeof(__pyx_k__newaxis), 0, 0, 1, 1}, - {&__pyx_n_s__norm, __pyx_k__norm, sizeof(__pyx_k__norm), 0, 0, 1, 1}, - {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, - {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, - {&__pyx_n_s__old_center, __pyx_k__old_center, sizeof(__pyx_k__old_center), 0, 0, 1, 1}, - {&__pyx_n_s__old_count, __pyx_k__old_count, sizeof(__pyx_k__old_count), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__sample_idx, __pyx_k__sample_idx, sizeof(__pyx_k__sample_idx), 0, 0, 1, 1}, - {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, - {&__pyx_n_s__sp, __pyx_k__sp, sizeof(__pyx_k__sp), 0, 0, 1, 1}, - {&__pyx_n_s__squared_diff, __pyx_k__squared_diff, sizeof(__pyx_k__squared_diff), 0, 0, 1, 1}, - {&__pyx_n_s__where, __pyx_k__where, sizeof(__pyx_k__where), 0, 0, 1, 1}, - {&__pyx_n_s__x_squared_norms, __pyx_k__x_squared_norms, sizeof(__pyx_k__x_squared_norms), 0, 0, 1, 1}, - {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1}, + {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0}, + {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0}, + {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, + {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_kp_s_Volumes_LocalDataHD_LocalScratc, __pyx_k_Volumes_LocalDataHD_LocalScratc, sizeof(__pyx_k_Volumes_LocalDataHD_LocalScratc), 0, 0, 1, 0}, + {&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1}, + {&__pyx_n_s_X_data, __pyx_k_X_data, sizeof(__pyx_k_X_data), 0, 0, 1, 1}, + {&__pyx_n_s_X_indices, __pyx_k_X_indices, sizeof(__pyx_k_X_indices), 0, 0, 1, 1}, + {&__pyx_n_s_X_indptr, __pyx_k_X_indptr, sizeof(__pyx_k_X_indptr), 0, 0, 1, 1}, + {&__pyx_n_s__12, __pyx_k__12, sizeof(__pyx_k__12), 0, 0, 1, 1}, + {&__pyx_n_s_abs, __pyx_k_abs, sizeof(__pyx_k_abs), 0, 0, 1, 1}, + {&__pyx_n_s_argsort, __pyx_k_argsort, sizeof(__pyx_k_argsort), 0, 0, 1, 1}, + {&__pyx_n_s_bincount, __pyx_k_bincount, sizeof(__pyx_k_bincount), 0, 0, 1, 1}, + {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, + {&__pyx_n_s_center_diff, __pyx_k_center_diff, sizeof(__pyx_k_center_diff), 0, 0, 1, 1}, + {&__pyx_n_s_center_idx, __pyx_k_center_idx, sizeof(__pyx_k_center_idx), 0, 0, 1, 1}, + {&__pyx_n_s_centers, __pyx_k_centers, sizeof(__pyx_k_centers), 0, 0, 1, 1}, + {&__pyx_n_s_centers_dense, __pyx_k_centers_dense, sizeof(__pyx_k_centers_dense), 0, 0, 1, 1}, + {&__pyx_n_s_centers_sparse, __pyx_k_centers_sparse, sizeof(__pyx_k_centers_sparse), 0, 0, 1, 1}, + {&__pyx_n_s_cluster_id, __pyx_k_cluster_id, sizeof(__pyx_k_cluster_id), 0, 0, 1, 1}, + {&__pyx_n_s_compute_squared_diff, __pyx_k_compute_squared_diff, sizeof(__pyx_k_compute_squared_diff), 0, 0, 1, 1}, + {&__pyx_n_s_counts, __pyx_k_counts, sizeof(__pyx_k_counts), 0, 0, 1, 1}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_distances, __pyx_k_distances, sizeof(__pyx_k_distances), 0, 0, 1, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_empty_clusters, __pyx_k_empty_clusters, sizeof(__pyx_k_empty_clusters), 0, 0, 1, 1}, + {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, + {&__pyx_n_s_far_from_centers, __pyx_k_far_from_centers, sizeof(__pyx_k_far_from_centers), 0, 0, 1, 1}, + {&__pyx_n_s_feature_idx, __pyx_k_feature_idx, sizeof(__pyx_k_feature_idx), 0, 0, 1, 1}, + {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1}, + {&__pyx_n_s_indptr, __pyx_k_indptr, sizeof(__pyx_k_indptr), 0, 0, 1, 1}, + {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1}, + {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1}, + {&__pyx_n_s_labels, __pyx_k_labels, sizeof(__pyx_k_labels), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_mini_batch_update_csr, __pyx_k_mini_batch_update_csr, sizeof(__pyx_k_mini_batch_update_csr), 0, 0, 1, 1}, + {&__pyx_n_s_minlength, __pyx_k_minlength, sizeof(__pyx_k_minlength), 0, 0, 1, 1}, + {&__pyx_n_s_n_clusters, __pyx_k_n_clusters, sizeof(__pyx_k_n_clusters), 0, 0, 1, 1}, + {&__pyx_n_s_n_features, __pyx_k_n_features, sizeof(__pyx_k_n_features), 0, 0, 1, 1}, + {&__pyx_n_s_n_samples, __pyx_k_n_samples, sizeof(__pyx_k_n_samples), 0, 0, 1, 1}, + {&__pyx_n_s_n_samples_in_cluster, __pyx_k_n_samples_in_cluster, sizeof(__pyx_k_n_samples_in_cluster), 0, 0, 1, 1}, + {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0}, + {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0}, + {&__pyx_n_s_nearest_center, __pyx_k_nearest_center, sizeof(__pyx_k_nearest_center), 0, 0, 1, 1}, + {&__pyx_n_s_new_center, __pyx_k_new_center, sizeof(__pyx_k_new_center), 0, 0, 1, 1}, + {&__pyx_n_s_new_count, __pyx_k_new_count, sizeof(__pyx_k_new_count), 0, 0, 1, 1}, + {&__pyx_n_s_newaxis, __pyx_k_newaxis, sizeof(__pyx_k_newaxis), 0, 0, 1, 1}, + {&__pyx_n_s_norm, __pyx_k_norm, sizeof(__pyx_k_norm), 0, 0, 1, 1}, + {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, + {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_n_s_old_center, __pyx_k_old_center, sizeof(__pyx_k_old_center), 0, 0, 1, 1}, + {&__pyx_n_s_old_count, __pyx_k_old_count, sizeof(__pyx_k_old_count), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_releasebuffer, __pyx_k_pyx_releasebuffer, sizeof(__pyx_k_pyx_releasebuffer), 0, 0, 1, 1}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_sample_idx, __pyx_k_sample_idx, sizeof(__pyx_k_sample_idx), 0, 0, 1, 1}, + {&__pyx_n_s_scipy_sparse, __pyx_k_scipy_sparse, sizeof(__pyx_k_scipy_sparse), 0, 0, 1, 1}, + {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, + {&__pyx_n_s_sklearn_cluster__k_means, __pyx_k_sklearn_cluster__k_means, sizeof(__pyx_k_sklearn_cluster__k_means), 0, 0, 1, 1}, + {&__pyx_n_s_sp, __pyx_k_sp, sizeof(__pyx_k_sp), 0, 0, 1, 1}, + {&__pyx_n_s_squared_diff, __pyx_k_squared_diff, sizeof(__pyx_k_squared_diff), 0, 0, 1, 1}, + {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0}, + {&__pyx_n_s_utils_extmath, __pyx_k_utils_extmath, sizeof(__pyx_k_utils_extmath), 0, 0, 1, 1}, + {&__pyx_n_s_utils_fixes, __pyx_k_utils_fixes, sizeof(__pyx_k_utils_fixes), 0, 0, 1, 1}, + {&__pyx_n_s_where, __pyx_k_where, sizeof(__pyx_k_where), 0, 0, 1, 1}, + {&__pyx_n_s_x_squared_norms, __pyx_k_x_squared_norms, sizeof(__pyx_k_x_squared_norms), 0, 0, 1, 1}, + {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -6990,162 +8289,162 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "sklearn/cluster/_k_means.pyx":208 + /* "sklearn/cluster/_k_means.pyx":293 * # weight w.r.t. the new data that will be incrementally contributed * if compute_squared_diff: * old_center[:] = centers[center_idx] # <<<<<<<<<<<<<< * centers[center_idx] *= old_count * */ - __pyx_k_slice_2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_slice_2); - __Pyx_GIVEREF(__pyx_k_slice_2); + __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_slice_); + __Pyx_GIVEREF(__pyx_slice_); - /* "sklearn/cluster/_k_means.pyx":281 + /* "sklearn/cluster/_k_means.pyx":366 * if len(empty_clusters): * # find points to reassign empty clusters to * far_from_centers = distances.argsort()[::-1] # <<<<<<<<<<<<<< * * for i, cluster_id in enumerate(empty_clusters): */ - __pyx_k_slice_3 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_k_slice_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_slice_3); - __Pyx_GIVEREF(__pyx_k_slice_3); + __pyx_slice__2 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_slice__2); + __Pyx_GIVEREF(__pyx_slice__2); - /* "sklearn/cluster/_k_means.pyx":293 - * centers[labels[i], j] += X[i, j] + /* "sklearn/cluster/_k_means.pyx":379 * + * # todo center computation needs to be aware of the distance measure * centers /= n_samples_in_cluster[:, np.newaxis] # <<<<<<<<<<<<<< * * return centers */ - __pyx_k_slice_4 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_slice_4); - __Pyx_GIVEREF(__pyx_k_slice_4); + __pyx_slice__3 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_slice__3); + __Pyx_GIVEREF(__pyx_slice__3); - /* "sklearn/cluster/_k_means.pyx":342 + /* "sklearn/cluster/_k_means.pyx":428 * if empty_clusters.shape[0] > 0: * # find points to reassign empty clusters to * far_from_centers = distances.argsort()[::-1] # <<<<<<<<<<<<<< * * for i in range(empty_clusters.shape[0]): */ - __pyx_k_slice_5 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_k_slice_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_slice_5); - __Pyx_GIVEREF(__pyx_k_slice_5); + __pyx_slice__4 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_slice__4); + __Pyx_GIVEREF(__pyx_slice__4); - /* "sklearn/cluster/_k_means.pyx":356 - * add_row_csr(data, indices, indptr, i, centers[labels[i]]) + /* "sklearn/cluster/_k_means.pyx":443 * + * # todo center computation needs to be aware of the distance measure * centers /= n_samples_in_cluster[:, np.newaxis] # <<<<<<<<<<<<<< * * return centers */ - __pyx_k_slice_6 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_slice_6); - __Pyx_GIVEREF(__pyx_k_slice_6); + __pyx_slice__5 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_slice__5); + __Pyx_GIVEREF(__pyx_slice__5); - /* "numpy.pxd":215 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":215 * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) */ - __pyx_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_8); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); - /* "numpy.pxd":219 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":219 * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< * * info.buf = PyArray_DATA(self) */ - __pyx_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_9)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_10); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); - /* "numpy.pxd":257 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":257 * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" */ - __pyx_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_11)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_12); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); - /* "numpy.pxd":799 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":799 * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< * * if ((child.byteorder == c'>' and little_endian) or */ - __pyx_k_tuple_15 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_14)); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_15); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); - /* "numpy.pxd":803 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":803 * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * # One could encode it in the format string and have Cython * # complain instead, BUT: < and > in format strings also imply */ - __pyx_k_tuple_16 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_11)); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_16); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); - /* "numpy.pxd":823 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":823 * t = child.type_num * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< * * # Until ticket #99 is fixed, use integers to avoid warnings */ - __pyx_k_tuple_18 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_17)); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_18); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); - /* "sklearn/cluster/_k_means.pyx":141 + /* "sklearn/cluster/_k_means.pyx":226 * @cython.wraparound(False) * @cython.cdivision(True) * def _mini_batch_update_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< * np.ndarray[DOUBLE, ndim=2] centers, * np.ndarray[INT, ndim=1] counts, */ - __pyx_k_tuple_23 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__X), ((PyObject *)__pyx_n_s__x_squared_norms), ((PyObject *)__pyx_n_s__centers), ((PyObject *)__pyx_n_s__counts), ((PyObject *)__pyx_n_s__nearest_center), ((PyObject *)__pyx_n_s__old_center), ((PyObject *)__pyx_n_s_1), ((PyObject *)__pyx_n_s__X_data), ((PyObject *)__pyx_n_s__X_indices), ((PyObject *)__pyx_n_s__X_indptr), ((PyObject *)__pyx_n_s__n_samples), ((PyObject *)__pyx_n_s__n_clusters), ((PyObject *)__pyx_n_s__n_features), ((PyObject *)__pyx_n_s__sample_idx), ((PyObject *)__pyx_n_s__center_idx), ((PyObject *)__pyx_n_s__feature_idx), ((PyObject *)__pyx_n_s__k), ((PyObject *)__pyx_n_s__old_count), ((PyObject *)__pyx_n_s__new_count), ((PyObject *)__pyx_n_s__center_diff), ((PyObject *)__pyx_n_s__squared_diff)); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_23); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); - __pyx_k_codeobj_24 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_26, __pyx_n_s_25, 141, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__13 = PyTuple_Pack(21, __pyx_n_s_X, __pyx_n_s_x_squared_norms, __pyx_n_s_centers, __pyx_n_s_counts, __pyx_n_s_nearest_center, __pyx_n_s_old_center, __pyx_n_s_compute_squared_diff, __pyx_n_s_X_data, __pyx_n_s_X_indices, __pyx_n_s_X_indptr, __pyx_n_s_n_samples, __pyx_n_s_n_clusters, __pyx_n_s_n_features, __pyx_n_s_sample_idx, __pyx_n_s_center_idx, __pyx_n_s_feature_idx, __pyx_n_s_k, __pyx_n_s_old_count, __pyx_n_s_new_count, __pyx_n_s_center_diff, __pyx_n_s_squared_diff); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Volumes_LocalDataHD_LocalScratc, __pyx_n_s_mini_batch_update_csr, 226, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/cluster/_k_means.pyx":244 + /* "sklearn/cluster/_k_means.pyx":329 * @cython.wraparound(False) * @cython.cdivision(True) * def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< * np.ndarray[INT, ndim=1] labels, int n_clusters, * np.ndarray[DOUBLE, ndim=1] distances): */ - __pyx_k_tuple_29 = PyTuple_Pack(15, ((PyObject *)__pyx_n_s__X), ((PyObject *)__pyx_n_s__labels), ((PyObject *)__pyx_n_s__n_clusters), ((PyObject *)__pyx_n_s__distances), ((PyObject *)__pyx_n_s__n_samples), ((PyObject *)__pyx_n_s__n_features), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__j), ((PyObject *)__pyx_n_s__c), ((PyObject *)__pyx_n_s__centers), ((PyObject *)__pyx_n_s_28), ((PyObject *)__pyx_n_s__empty_clusters), ((PyObject *)__pyx_n_s__far_from_centers), ((PyObject *)__pyx_n_s__cluster_id), ((PyObject *)__pyx_n_s__new_center)); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_29); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); - __pyx_k_codeobj_30 = (PyObject*)__Pyx_PyCode_New(4, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_26, __pyx_n_s___centers_dense, 244, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__15 = PyTuple_Pack(15, __pyx_n_s_X, __pyx_n_s_labels, __pyx_n_s_n_clusters, __pyx_n_s_distances, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_c, __pyx_n_s_centers, __pyx_n_s_n_samples_in_cluster, __pyx_n_s_empty_clusters, __pyx_n_s_far_from_centers, __pyx_n_s_cluster_id, __pyx_n_s_new_center); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(4, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Volumes_LocalDataHD_LocalScratc, __pyx_n_s_centers_dense, 329, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/cluster/_k_means.pyx":298 + /* "sklearn/cluster/_k_means.pyx":384 * * * def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, # <<<<<<<<<<<<<< * np.ndarray[DOUBLE, ndim=1] distances): * """M step of the K-means EM algorithm */ - __pyx_k_tuple_31 = PyTuple_Pack(14, ((PyObject *)__pyx_n_s__X), ((PyObject *)__pyx_n_s__labels), ((PyObject *)__pyx_n_s__n_clusters), ((PyObject *)__pyx_n_s__distances), ((PyObject *)__pyx_n_s__n_features), ((PyObject *)__pyx_n_s__cluster_id), ((PyObject *)__pyx_n_s__data), ((PyObject *)__pyx_n_s__indices), ((PyObject *)__pyx_n_s__indptr), ((PyObject *)__pyx_n_s__centers), ((PyObject *)__pyx_n_s__far_from_centers), ((PyObject *)__pyx_n_s_28), ((PyObject *)__pyx_n_s__empty_clusters), ((PyObject *)__pyx_n_s__i)); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_31); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31)); - __pyx_k_codeobj_32 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_26, __pyx_n_s___centers_sparse, 298, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__17 = PyTuple_Pack(14, __pyx_n_s_X, __pyx_n_s_labels, __pyx_n_s_n_clusters, __pyx_n_s_distances, __pyx_n_s_n_features, __pyx_n_s_cluster_id, __pyx_n_s_data, __pyx_n_s_indices, __pyx_n_s_indptr, __pyx_n_s_centers, __pyx_n_s_far_from_centers, __pyx_n_s_n_samples_in_cluster, __pyx_n_s_empty_clusters, __pyx_n_s_i); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Volumes_LocalDataHD_LocalScratc, __pyx_n_s_centers_sparse, 384, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -7155,10 +8454,10 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_float_0_ = PyFloat_FromDouble(0.); if (unlikely(!__pyx_float_0_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -7217,14 +8516,6 @@ PyMODINIT_FUNC PyInit__k_means(void) if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_INCREF(__pyx_d); - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "sklearn.cluster._k_means")) { - if (unlikely(PyDict_SetItemString(modules, "sklearn.cluster._k_means", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); @@ -7236,8 +8527,16 @@ PyMODINIT_FUNC PyInit__k_means(void) if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif if (__pyx_module_is_main_sklearn__cluster___k_means) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!PyDict_GetItemString(modules, "sklearn.cluster._k_means")) { + if (unlikely(PyDict_SetItemString(modules, "sklearn.cluster._k_means", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } } + #endif /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ @@ -7273,9 +8572,9 @@ PyMODINIT_FUNC PyInit__k_means(void) * import scipy.sparse as sp * cimport numpy as np */ - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__np, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "sklearn/cluster/_k_means.pyx":12 @@ -7287,13 +8586,13 @@ PyMODINIT_FUNC PyInit__k_means(void) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_n_s_20)); - PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s_20)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s_20)); - __pyx_t_3 = __Pyx_Import(((PyObject *)__pyx_n_s_19), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_s__12); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s__12); + __Pyx_GIVEREF(__pyx_n_s__12); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_scipy_sparse, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s__sp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sp, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "sklearn/cluster/_k_means.pyx":16 @@ -7305,15 +8604,15 @@ PyMODINIT_FUNC PyInit__k_means(void) */ __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_n_s__norm)); - PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__norm)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__norm)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_21), ((PyObject *)__pyx_t_3), 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_s_norm); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_norm); + __Pyx_GIVEREF(__pyx_n_s_norm); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_utils_extmath, __pyx_t_3, 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s__norm); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_norm); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__norm, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_norm, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -7326,15 +8625,15 @@ PyMODINIT_FUNC PyInit__k_means(void) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_n_s__bincount)); - PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__bincount)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bincount)); - __pyx_t_3 = __Pyx_Import(((PyObject *)__pyx_n_s_22), ((PyObject *)__pyx_t_2), 2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_s_bincount); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_bincount); + __Pyx_GIVEREF(__pyx_n_s_bincount); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_utils_fixes, __pyx_t_2, 2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s__bincount); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_bincount); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__bincount, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_bincount, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -7347,40 +8646,40 @@ PyMODINIT_FUNC PyInit__k_means(void) */ import_array(); - /* "sklearn/cluster/_k_means.pyx":141 + /* "sklearn/cluster/_k_means.pyx":226 * @cython.wraparound(False) * @cython.cdivision(True) * def _mini_batch_update_csr(X, np.ndarray[DOUBLE, ndim=1] x_squared_norms, # <<<<<<<<<<<<<< * np.ndarray[DOUBLE, ndim=2] centers, * np.ndarray[INT, ndim=1] counts, */ - __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_5_mini_batch_update_csr, NULL, __pyx_n_s_27); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_9_mini_batch_update_csr, NULL, __pyx_n_s_sklearn_cluster__k_means); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_25, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_mini_batch_update_csr, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/cluster/_k_means.pyx":244 + /* "sklearn/cluster/_k_means.pyx":329 * @cython.wraparound(False) * @cython.cdivision(True) * def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, # <<<<<<<<<<<<<< * np.ndarray[INT, ndim=1] labels, int n_clusters, * np.ndarray[DOUBLE, ndim=1] distances): */ - __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_7_centers_dense, NULL, __pyx_n_s_27); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_11_centers_dense, NULL, __pyx_n_s_sklearn_cluster__k_means); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s___centers_dense, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_centers_dense, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/cluster/_k_means.pyx":298 + /* "sklearn/cluster/_k_means.pyx":384 * * * def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, # <<<<<<<<<<<<<< * np.ndarray[DOUBLE, ndim=1] distances): * """M step of the K-means EM algorithm */ - __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_9_centers_sparse, NULL, __pyx_n_s_27); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_7cluster_8_k_means_13_centers_sparse, NULL, __pyx_n_s_sklearn_cluster__k_means); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s___centers_sparse, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_centers_sparse, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "sklearn/cluster/_k_means.pyx":1 @@ -7389,11 +8688,11 @@ PyMODINIT_FUNC PyInit__k_means(void) * # on this specific use case. */ __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (PyDict_SetItem(__pyx_d, __pyx_n_s____test__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "numpy.pxd":975 + /* "/Volumes/LocalDataHD/virtualenv/2.7.5-dev/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd":976 * arr.base = baseptr * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -7444,7 +8743,7 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else - "name '%s' is not defined", PyString_AS_STRING(name)); + "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; @@ -7474,8 +8773,10 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, Py_INCREF(Py_None); (*frame)->f_trace = Py_None; } +#if PY_VERSION_HEX < 0x030400B1 } else { (*frame)->f_tstate = tstate; +#endif } (*frame)->f_lineno = firstlineno; tstate->use_tracing = 0; @@ -8089,16 +9390,82 @@ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { return result; } -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); + if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_Clear(); + else + return NULL; + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { @@ -8133,10 +9500,18 @@ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyOb } static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, - CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, + int full_traceback) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + if (full_traceback) { + Py_XINCREF(old_exc); + Py_XINCREF(old_val); + Py_XINCREF(old_tb); + __Pyx_ErrRestore(old_exc, old_val, old_tb); + PyErr_PrintEx(1); + } #if PY_MAJOR_VERSION < 3 ctx = PyString_FromString(name); #else @@ -8171,7 +9546,7 @@ static void __Pyx_RaiseArgtupleInvalid( more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } @@ -8275,12 +9650,12 @@ static int __Pyx_ParseOptionalKeywords( goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); + "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", + "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", @@ -8290,102 +9665,42 @@ static int __Pyx_ParseOptionalKeywords( return -1; } -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, +static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); +} +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { - if (!type) { - PyErr_Format(PyExc_SystemError, "Missing type object"); + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); return 0; } if (none_allowed && obj == Py_None) return 1; else if (exact) { - if (Py_TYPE(obj) == type) return 1; + if (likely(Py_TYPE(obj) == type)) return 1; + #if PY_MAJOR_VERSION == 2 + else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif } else { - if (PyObject_TypeCheck(obj, type)) return 1; + if (likely(PyObject_TypeCheck(obj, type))) return 1; } - PyErr_Format(PyExc_TypeError, - "Argument '%s' has incorrect type (expected %s, got %s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); + __Pyx_RaiseArgumentTypeInvalid(name, obj, type); return 0; } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); - if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, - int is_list, int wraparound, int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (is_list || PyList_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) - PyErr_Clear(); - else - return NULL; - } - } - return m->sq_item(o, i); - } - } -#else - if (is_list || PySequence_Check(o)) { - return PySequence_GetItem(o, i); +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; } static CYTHON_INLINE int __Pyx_PyObject_SetSlice( @@ -8480,7 +9795,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( return result; } PyErr_Format(PyExc_TypeError, - "'%.200s' object does not support slice %s", + "'%.200s' object does not support slice %.10s", Py_TYPE(obj)->tp_name, value ? "assignment" : "deletion"); bad: return -1; @@ -8539,7 +9854,7 @@ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { } static void __Pyx_RaiseBufferFallbackError(void) { - PyErr_Format(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); } @@ -8634,27 +9949,40 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + if (PyObject_IsSubclass(instance_class, type)) { + type = instance_class; + } else { + instance_class = NULL; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } } } else { PyErr_SetString(PyExc_TypeError, @@ -8707,7 +10035,7 @@ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, - "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack", + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", index, (index == 1) ? "" : "s"); } @@ -8715,51 +10043,6 @@ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); } -static CYTHON_INLINE int __Pyx_IterFinish(void) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - PyObject* exc_type = tstate->curexc_type; - if (unlikely(exc_type)) { - if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { - PyObject *exc_value, *exc_tb; - exc_value = tstate->curexc_value; - exc_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - Py_DECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_tb); - return 0; - } else { - return -1; - } - } - return 0; -#else - if (unlikely(PyErr_Occurred())) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; - } else { - return -1; - } - } - return 0; -#endif -} - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } else { - return __Pyx_IterFinish(); - } - return 0; -} - static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { @@ -8782,7 +10065,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict) { PyObject *getbuffer_cobj = PyObject_GetItem( - obj->ob_type->tp_dict, __pyx_n_s____pyx_getbuffer); + obj->ob_type->tp_dict, __pyx_n_s_pyx_getbuffer); if (getbuffer_cobj) { getbufferproc func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); Py_DECREF(getbuffer_cobj); @@ -8794,7 +10077,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { } } #endif - PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); + PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name); #if PY_VERSION_HEX < 0x02060000 fail: #endif @@ -8813,7 +10096,7 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict) { PyObject *releasebuffer_cobj = PyObject_GetItem( - obj->ob_type->tp_dict, __pyx_n_s____pyx_releasebuffer); + obj->ob_type->tp_dict, __pyx_n_s_pyx_releasebuffer); if (releasebuffer_cobj) { releasebufferproc func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); Py_DECREF(releasebuffer_cobj); @@ -8846,7 +10129,7 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { PyObject *list; #if PY_VERSION_HEX < 0x03030000 PyObject *py_import; - py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s____import__); + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif @@ -8886,144 +10169,483 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { PyErr_Clear(); } } - level = 0; /* try absolute import on failure */ + level = 0; /* try absolute import on failure */ + } + #endif + if (!module) { + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } + #else + if (level>0) { + PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); + goto bad; + } + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); + #endif +bad: + #if PY_VERSION_HEX < 0x03030000 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func) \ + { \ + func_type value = func(x); \ + if (sizeof(target_type) < sizeof(func_type)) { \ + if (unlikely(value != (func_type) (target_type) value)) { \ + func_type zero = 0; \ + PyErr_SetString(PyExc_OverflowError, \ + (is_unsigned && unlikely(value < zero)) ? \ + "can't convert negative value to " #target_type : \ + "value too large to convert to " #target_type); \ + return (target_type) -1; \ + } \ + } \ + return (target_type) value; \ + } + +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; + } + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(int) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(int) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong) + } else if (sizeof(int) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { + const unsigned int neg_one = (unsigned int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(unsigned int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(unsigned int) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(unsigned int) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(unsigned int), + little, !is_unsigned); + } +} + +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { + const unsigned int neg_one = (unsigned int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(unsigned int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; + } + return (unsigned int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(unsigned int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (unsigned int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; + } + if (sizeof(unsigned int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(unsigned int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(unsigned int) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(unsigned int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(unsigned int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyLong_AsLong) + } else if (sizeof(unsigned int) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long long, PyLong_AsLongLong) + } } - #endif - if (!module) { - #if PY_VERSION_HEX < 0x03030000 - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - #else - module = PyImport_ImportModuleLevelObject( - name, global_dict, empty_dict, list, level); - #endif + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + unsigned int val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (unsigned int) -1; } + } else { + unsigned int val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned int) -1; + val = __Pyx_PyInt_As_unsigned_int(tmp); + Py_DECREF(tmp); + return val; } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; +} + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(long) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - #if PY_VERSION_HEX < 0x03030000 - Py_XDECREF(py_import); - #endif - Py_XDECREF(empty_list); - Py_XDECREF(empty_dict); - return module; } -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int32(npy_int32 val) { - const npy_int32 neg_one = (npy_int32)-1, const_zero = (npy_int32)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(npy_int32) == sizeof(char)) || - (sizeof(npy_int32) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(npy_int32) == sizeof(int)) || - (sizeof(npy_int32) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(npy_int32) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int32(npy_int32 value) { + const npy_int32 neg_one = (npy_int32) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(npy_int32) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(npy_int32) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(npy_int32) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } } else { + if (sizeof(npy_int32) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(npy_int32) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; + unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(npy_int32), little, !is_unsigned); } } -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t val) { - const Py_intptr_t neg_one = (Py_intptr_t)-1, const_zero = (Py_intptr_t)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(Py_intptr_t) == sizeof(char)) || - (sizeof(Py_intptr_t) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(Py_intptr_t) == sizeof(int)) || - (sizeof(Py_intptr_t) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(Py_intptr_t) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(int) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) { + const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(Py_intptr_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } } else { + if (sizeof(Py_intptr_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; + unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(Py_intptr_t), little, !is_unsigned); } } -static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_from_py_Py_intptr_t(PyObject* x) { - const Py_intptr_t neg_one = (Py_intptr_t)-1, const_zero = (Py_intptr_t)0; - const int is_unsigned = const_zero < neg_one; - if (sizeof(Py_intptr_t) == sizeof(char)) { - if (is_unsigned) - return (Py_intptr_t)__Pyx_PyInt_AsUnsignedChar(x); - else - return (Py_intptr_t)__Pyx_PyInt_AsSignedChar(x); - } else if (sizeof(Py_intptr_t) == sizeof(short)) { - if (is_unsigned) - return (Py_intptr_t)__Pyx_PyInt_AsUnsignedShort(x); - else - return (Py_intptr_t)__Pyx_PyInt_AsSignedShort(x); - } else if (sizeof(Py_intptr_t) == sizeof(int)) { - if (is_unsigned) - return (Py_intptr_t)__Pyx_PyInt_AsUnsignedInt(x); - else - return (Py_intptr_t)__Pyx_PyInt_AsSignedInt(x); - } else if (sizeof(Py_intptr_t) == sizeof(long)) { - if (is_unsigned) - return (Py_intptr_t)__Pyx_PyInt_AsUnsignedLong(x); - else - return (Py_intptr_t)__Pyx_PyInt_AsSignedLong(x); - } else if (sizeof(Py_intptr_t) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return (Py_intptr_t)__Pyx_PyInt_AsUnsignedLongLong(x); - else - return (Py_intptr_t)__Pyx_PyInt_AsSignedLongLong(x); - } else { - #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); - #else - Py_intptr_t val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_As_Py_intptr_t(PyObject *x) { + const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(Py_intptr_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to Py_intptr_t"); + return (Py_intptr_t) -1; + } + return (Py_intptr_t) val; } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(Py_intptr_t)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (Py_intptr_t) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to Py_intptr_t"); + return (Py_intptr_t) -1; + } + if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(Py_intptr_t)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(Py_intptr_t) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(Py_intptr_t) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(Py_intptr_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, PyLong_AsLong) + } else if (sizeof(Py_intptr_t) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long long, PyLong_AsLongLong) + } } - #endif - return (Py_intptr_t)-1; + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + Py_intptr_t val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (Py_intptr_t) -1; + } + } else { + Py_intptr_t val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (Py_intptr_t) -1; + val = __Pyx_PyInt_As_Py_intptr_t(tmp); + Py_DECREF(tmp); + return val; } } @@ -9203,422 +10825,118 @@ static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_from_py_Py_intptr_t(PyObject* x) { return z; } static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } - #if 1 - static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { - #if !defined(HAVE_HYPOT) || defined(_MSC_VER) - return sqrt(z.real*z.real + z.imag*z.imag); - #else - return hypot(z.real, z.imag); - #endif - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - double r, lnr, theta, z_r, z_theta; - if (b.imag == 0 && b.real == (int)b.real) { - if (b.real < 0) { - double denom = a.real * a.real + a.imag * a.imag; - a.real = a.real / denom; - a.imag = -a.imag / denom; - b.real = -b.real; - } - switch ((int)b.real) { - case 0: - z.real = 1; - z.imag = 0; - return z; - case 1: - return a; - case 2: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(a, a); - case 3: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(z, a); - case 4: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(z, z); - } - } - if (a.imag == 0) { - if (a.real == 0) { - return a; - } - r = a.real; - theta = 0; - } else { - r = __Pyx_c_abs(a); - theta = atan2(a.imag, a.real); - } - lnr = log(r); - z_r = exp(lnr * b.real - theta * b.imag); - z_theta = theta * b.real + lnr * b.imag; - z.real = z_r * cos(z_theta); - z.imag = z_r * sin(z_theta); - return z; - } - #endif -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; + return (a.real == 0) && (a.imag == 0); } - return (int)__Pyx_PyInt_AsLong(x); -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { + __pyx_t_double_complex z; + z.real = a.real; + z.imag = -a.imag; + return z; + } + #if 1 + static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { + #if !defined(HAVE_HYPOT) || defined(_MSC_VER) + return sqrt(z.real*z.real + z.imag*z.imag); + #else + return hypot(z.real, z.imag); + #endif } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned long) ((PyLongObject*)x)->ob_digit[0]; + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + double r, lnr, theta, z_r, z_theta; + if (b.imag == 0 && b.real == (int)b.real) { + if (b.real < 0) { + double denom = a.real * a.real + a.imag * a.imag; + a.real = a.real / denom; + a.imag = -a.imag / denom; + b.real = -b.real; + } + switch ((int)b.real) { + case 0: + z.real = 1; + z.imag = 0; + return z; + case 1: + return a; + case 2: + z = __Pyx_c_prod(a, a); + return __Pyx_c_prod(a, a); + case 3: + z = __Pyx_c_prod(a, a); + return __Pyx_c_prod(z, a); + case 4: + z = __Pyx_c_prod(a, a); + return __Pyx_c_prod(z, z); } } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned long) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned long) ((PyLongObject*)x)->ob_digit[0]; + if (a.imag == 0) { + if (a.real == 0) { + return a; } + r = a.real; + theta = 0; + } else { + r = __Pyx_c_abs(a); + theta = atan2(a.imag, a.real); } -#endif -#endif - return (unsigned long)PyLong_AsLong(x); + lnr = log(r); + z_r = exp(lnr * b.real - theta * b.imag); + z_theta = theta * b.real + lnr * b.imag; + z.real = z_r * cos(z_theta); + z.imag = z_r * sin(z_theta); + return z; } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} + #endif +#endif #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif #endif -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG) } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; } -#endif -#endif - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; + return (long) val; } - return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS + #if CYTHON_USE_PYLONG_INTERNALS if (sizeof(digit) <= sizeof(long)) { switch (Py_SIZE(x)) { case 0: return 0; case 1: return (long) ((PyLongObject*)x)->ob_digit[0]; } } -#endif + #endif #endif if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); - return (long)-1; + return (long) -1; + } + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(long) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong) } - return (long)PyLong_AsUnsignedLong(x); } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS + #if CYTHON_USE_PYLONG_INTERNALS if (sizeof(digit) <= sizeof(long)) { switch (Py_SIZE(x)) { case 0: return 0; @@ -9626,198 +10944,46 @@ static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { case -1: return -(long) ((PyLongObject*)x)->ob_digit[0]; } } + #endif #endif -#endif - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (signed long) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(signed long) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(signed long) ((PyLongObject*)x)->ob_digit[0]; - } + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong) + } else if (sizeof(long) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong) } -#endif -#endif - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; } #endif -#endif - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); + return (long) -1; } } else { - signed PY_LONG_LONG val; + long val; PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } @@ -9887,7 +11053,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", + "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } @@ -9915,7 +11081,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class } else if ((size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", + "%.200s.%.200s has the wrong size, try recompiling", module_name, class_name); goto bad; } @@ -9942,14 +11108,14 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** cobj = PyDict_GetItemString(d, funcname); if (!cobj) { PyErr_Format(PyExc_ImportError, - "%s does not export expected C function %s", + "%.200s does not export expected C function %.200s", PyModule_GetName(module), funcname); goto bad; } #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0) if (!PyCapsule_IsValid(cobj, sig)) { PyErr_Format(PyExc_TypeError, - "C function %s.%s has wrong signature (expected %s, got %s)", + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj)); goto bad; } @@ -9963,7 +11129,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } if (*s1 != *s2) { PyErr_Format(PyExc_TypeError, - "C function %s.%s has wrong signature (expected %s, got %s)", + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", PyModule_GetName(module), funcname, sig, desc); goto bad; } @@ -10221,10 +11387,16 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_ #endif /* PY_VERSION_HEX < 0x03030000 */ } else #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ +#if PY_VERSION_HEX >= 0x02060000 + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); - if (r < 0) { + if (unlikely(r < 0)) { return NULL; } else { return result; @@ -10269,7 +11441,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", + "__%.4s__ returned non-%.4s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; @@ -10281,9 +11453,35 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { } return res; } +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) + return PyInt_AS_LONG(b); +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + switch (Py_SIZE(b)) { + case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0]; + case 0: return 0; + case 1: return ((PyLongObject*)b)->ob_digit[0]; + } + #endif + #endif + #if PY_VERSION_HEX < 0x02060000 + return PyInt_AsSsize_t(b); + #else + return PyLong_AsSsize_t(b); + #endif + } + x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); @@ -10302,16 +11500,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); #endif } -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - if ((val != (unsigned PY_LONG_LONG)-1) || !PyErr_Occurred()) - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} #endif /* Py_PYTHON_H */ diff --git a/sklearn/cluster/_k_means.pyx b/sklearn/cluster/_k_means.pyx index 3fc4150d6ca23..82b981d44fc8f 100644 --- a/sklearn/cluster/_k_means.pyx +++ b/sklearn/cluster/_k_means.pyx @@ -26,6 +26,91 @@ cdef extern from "cblas.h": np.import_array() +@cython.boundscheck(False) +@cython.wraparound(False) +@cython.cdivision(True) +cpdef DOUBLE _assign_labels_array_L1(np.ndarray[DOUBLE, ndim=2] X, + np.ndarray[DOUBLE, ndim=2] centers, + np.ndarray[INT, ndim=1] labels, + np.ndarray[DOUBLE, ndim=1] distances): + """Compute label assignment and inertia for a dense array using the L1 norm + + Return the inertia (sum of squared distances to the centers). + """ + cdef: + unsigned int n_clusters = centers.shape[0] + unsigned int n_features = centers.shape[1] + unsigned int n_samples = X.shape[0] + unsigned int sample_idx, center_idx + unsigned int store_distances = 0 + DOUBLE inertia = 0.0 + DOUBLE min_dist + DOUBLE dist + + if n_samples == distances.shape[0]: + store_distances = 1 + + sum, abs = np.sum, np.abs + for sample_idx in range(n_samples): + min_dist = -1 + for center_idx in range(n_clusters): + dist = sum(abs(centers[center_idx] - X[sample_idx])) + if min_dist == -1 or dist < min_dist: + min_dist = dist + labels[sample_idx] = center_idx + + if store_distances: + distances[sample_idx] = min_dist + inertia += min_dist + + return inertia + + +@cython.boundscheck(False) +@cython.wraparound(False) +@cython.cdivision(True) +cpdef DOUBLE _assign_labels_csr_L1(X, np.ndarray[DOUBLE, ndim=2] centers, + np.ndarray[INT, ndim=1] labels, + np.ndarray[DOUBLE, ndim=1] distances): + """Compute label assignment and inertia for a dense array using the L1 norm + + Return the inertia (sum of squared distances to the centers). + """ + cdef: + np.ndarray[DOUBLE, ndim=1] X_data = X.data + np.ndarray[INT, ndim=1] X_indices = X.indices + np.ndarray[INT, ndim=1] X_indptr = X.indptr + unsigned int n_clusters = centers.shape[0] + unsigned int n_features = centers.shape[1] + unsigned int n_samples = X.shape[0] + unsigned int sample_idx, center_idx + unsigned int store_distances = 0 + unsigned int k + DOUBLE inertia = 0.0 + DOUBLE min_dist + DOUBLE dist + + if n_samples == distances.shape[0]: + store_distances = 1 + + sum, abs = np.sum, np.abs + for sample_idx in range(n_samples): + min_dist = -1 + for center_idx in range(n_clusters): + dist = 0.0 + for k in range(X_indptr[sample_idx], X_indptr[sample_idx + 1]): + dist += abs(centers[center_idx, X_indices[k]] - X_data[k]) + if min_dist == -1 or dist < min_dist: + min_dist = dist + labels[sample_idx] = center_idx + + if store_distances: + distances[sample_idx] = min_dist + inertia += min_dist + + return inertia + + @cython.boundscheck(False) @cython.wraparound(False) @cython.cdivision(True) @@ -290,6 +375,7 @@ def _centers_dense(np.ndarray[DOUBLE, ndim=2] X, for j in range(n_features): centers[labels[i], j] += X[i, j] + # todo center computation needs to be aware of the distance measure centers /= n_samples_in_cluster[:, np.newaxis] return centers @@ -353,6 +439,7 @@ def _centers_sparse(X, np.ndarray[INT, ndim=1] labels, n_clusters, for i in range(labels.shape[0]): add_row_csr(data, indices, indptr, i, centers[labels[i]]) + # todo center computation needs to be aware of the distance measure centers /= n_samples_in_cluster[:, np.newaxis] return centers