From bc706132db61f23629a607d843ff78ce5dc6f089 Mon Sep 17 00:00:00 2001 From: mz Date: Thu, 8 Jun 2017 10:43:10 +0200 Subject: [PATCH] Fix how values are accessed in when preparing cartograms due to change in api --- magrit_app/__init__.py | 2 +- magrit_app/helpers/cartogram_doug.c | 153 +++++++++++++------------- magrit_app/helpers/cartogram_doug.h | 2 +- magrit_app/helpers/cartogram_doug.pyx | 2 +- misc/Docker/app/Dockerfile | 2 +- misc/dockerfiles/Dockerfile | 2 +- 6 files changed, 81 insertions(+), 82 deletions(-) diff --git a/magrit_app/__init__.py b/magrit_app/__init__.py index e8e4b946e..054fa8369 100755 --- a/magrit_app/__init__.py +++ b/magrit_app/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -__version__ = '0.3.0' +__version__ = '0.3.1' diff --git a/magrit_app/helpers/cartogram_doug.c b/magrit_app/helpers/cartogram_doug.c index fb0ca1b07..257770225 100644 --- a/magrit_app/helpers/cartogram_doug.c +++ b/magrit_app/helpers/cartogram_doug.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.25.1 */ +/* Generated by Cython 0.25.2 */ /* BEGIN: Cython Metadata { @@ -16,7 +16,7 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) #error Cython requires Python 2.6+ or Python 3.2+. #else -#define CYTHON_ABI "0_25_1" +#define CYTHON_ABI "0_25_2" #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) @@ -199,7 +199,7 @@ END: Cython Metadata */ #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ - ((PyCFunction_Check(func) && METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST))) + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif @@ -352,10 +352,39 @@ END: Cython Metadata */ #define CYTHON_RESTRICT #endif #endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifndef CYTHON_INLINE - #if defined(__GNUC__) + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline @@ -423,26 +452,6 @@ static CYTHON_INLINE float __PYX_NAN() { #define CYTHON_WITHOUT_ASSERTIONS #endif -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif -#ifndef CYTHON_NCP_UNUSED -# if CYTHON_COMPILING_IN_CPYTHON -# define CYTHON_NCP_UNUSED -# else -# define CYTHON_NCP_UNUSED CYTHON_UNUSED -# endif -#endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; @@ -632,7 +641,7 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "magrit_app/helpers/cartogram_doug.pyx", "array.pxd", - "magrit_app/helpers/stringsource", + "stringsource", "type.pxd", "bool.pxd", "complex.pxd", @@ -1534,9 +1543,6 @@ static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); - /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value); @@ -1544,6 +1550,9 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp); static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + /* MemviewSliceCopyTemplate.proto */ static __Pyx_memviewslice __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, @@ -2680,7 +2689,7 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s * self.iterations = iterations * self.total_features = len(self.geodf) # <<<<<<<<<<<<<< * self.dForceReductionFactor = 0 - * self.values = geodf[[field_idx]].astype(float).values.T[0] + * self.values = geodf.T.iloc[field_idx].astype(float).values */ __pyx_t_2 = __pyx_v_self->geodf; __Pyx_INCREF(__pyx_t_2); @@ -2692,7 +2701,7 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s * self.iterations = iterations * self.total_features = len(self.geodf) * self.dForceReductionFactor = 0 # <<<<<<<<<<<<<< - * self.values = geodf[[field_idx]].astype(float).values.T[0] + * self.values = geodf.T.iloc[field_idx].astype(float).values * self.aLocal = malloc(self.total_features * sizeof(Holder)) */ __pyx_v_self->dForceReductionFactor = 0.0; @@ -2700,18 +2709,16 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s /* "magrit_app/helpers/cartogram_doug.pyx":86 * self.total_features = len(self.geodf) * self.dForceReductionFactor = 0 - * self.values = geodf[[field_idx]].astype(float).values.T[0] # <<<<<<<<<<<<<< + * self.values = geodf.T.iloc[field_idx].astype(float).values # <<<<<<<<<<<<<< * self.aLocal = malloc(self.total_features * sizeof(Holder)) * if not self.aLocal: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_field_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_geodf, __pyx_n_s_T); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_iloc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetItem(__pyx_v_geodf, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_field_idx, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) @@ -2763,12 +2770,6 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_T); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_4); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -2779,7 +2780,7 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s /* "magrit_app/helpers/cartogram_doug.pyx":87 * self.dForceReductionFactor = 0 - * self.values = geodf[[field_idx]].astype(float).values.T[0] + * self.values = geodf.T.iloc[field_idx].astype(float).values * self.aLocal = malloc(self.total_features * sizeof(Holder)) # <<<<<<<<<<<<<< * if not self.aLocal: * raise MemoryError() @@ -2787,7 +2788,7 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s __pyx_v_self->aLocal = ((Holder *)malloc((__pyx_v_self->total_features * (sizeof(Holder))))); /* "magrit_app/helpers/cartogram_doug.pyx":88 - * self.values = geodf[[field_idx]].astype(float).values.T[0] + * self.values = geodf.T.iloc[field_idx].astype(float).values * self.aLocal = malloc(self.total_features * sizeof(Holder)) * if not self.aLocal: # <<<<<<<<<<<<<< * raise MemoryError() @@ -2806,7 +2807,7 @@ static int __pyx_pf_10magrit_app_7helpers_14cartogram_doug_9Cartogram___init__(s PyErr_NoMemory(); __PYX_ERR(0, 89, __pyx_L1_error) /* "magrit_app/helpers/cartogram_doug.pyx":88 - * self.values = geodf[[field_idx]].astype(float).values.T[0] + * self.values = geodf.T.iloc[field_idx].astype(float).values * self.aLocal = malloc(self.total_features * sizeof(Holder)) * if not self.aLocal: # <<<<<<<<<<<<<< * raise MemoryError() @@ -18619,10 +18620,8 @@ static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, P PyCFunctionObject *func = (PyCFunctionObject*)func_obj; PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); - PyObject *result; - int flags; assert(PyCFunction_Check(func)); - assert(METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)); + assert(METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST))); assert(nargs >= 0); assert(nargs == 0 || args != NULL); /* _PyCFunction_FastCallDict() must not be called with an exception set, @@ -20946,24 +20945,24 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = (long) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { + const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { + if (sizeof(unsigned int) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { + } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(long) <= sizeof(long)) { + if (sizeof(unsigned int) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -20971,30 +20970,42 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), + return _PyLong_FromByteArray(bytes, sizeof(unsigned int), little, !is_unsigned); } } +/* MemviewDtypeToObject */ + static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp) { + return (PyObject *) PyFloat_FromDouble(*(double *) itemp); +} +static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj) { + double value = __pyx_PyFloat_AsDouble(obj); + if ((value == (double)-1) && PyErr_Occurred()) + return 0; + *(double *) itemp = value; + return 1; +} + /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { - const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(unsigned int) < sizeof(long)) { + if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { + } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(unsigned int) <= sizeof(long)) { + if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -21002,23 +21013,11 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(unsigned int), + return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } -/* MemviewDtypeToObject */ - static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp) { - return (PyObject *) PyFloat_FromDouble(*(double *) itemp); -} -static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj) { - double value = __pyx_PyFloat_AsDouble(obj); - if ((value == (double)-1) && PyErr_Occurred()) - return 0; - *(double *) itemp = value; - return 1; -} - /* MemviewSliceCopyTemplate */ static __Pyx_memviewslice __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, diff --git a/magrit_app/helpers/cartogram_doug.h b/magrit_app/helpers/cartogram_doug.h index d9918d0eb..f515f7cad 100644 --- a/magrit_app/helpers/cartogram_doug.h +++ b/magrit_app/helpers/cartogram_doug.h @@ -1,4 +1,4 @@ -/* Generated by Cython 0.25.1 */ +/* Generated by Cython 0.25.2 */ #ifndef __PYX_HAVE__magrit_app__helpers__cartogram_doug #define __PYX_HAVE__magrit_app__helpers__cartogram_doug diff --git a/magrit_app/helpers/cartogram_doug.pyx b/magrit_app/helpers/cartogram_doug.pyx index d8f7cf721..58d3cdcdf 100755 --- a/magrit_app/helpers/cartogram_doug.pyx +++ b/magrit_app/helpers/cartogram_doug.pyx @@ -83,7 +83,7 @@ cdef class Cartogram(object): self.iterations = iterations self.total_features = len(self.geodf) self.dForceReductionFactor = 0 - self.values = geodf[[field_idx]].astype(float).values.T[0] + self.values = geodf.T.iloc[field_idx].astype(float).values self.aLocal = malloc(self.total_features * sizeof(Holder)) if not self.aLocal: raise MemoryError() diff --git a/misc/Docker/app/Dockerfile b/misc/Docker/app/Dockerfile index 42dcbc253..b4b394ec2 100755 --- a/misc/Docker/app/Dockerfile +++ b/misc/Docker/app/Dockerfile @@ -73,7 +73,7 @@ RUN wget https://bootstrap.pypa.io/get-pip.py && python3.6 get-pip.py RUN cd /home/app/magrit/ \ && pip3.6 install -U -r requirements-dev.txt \ && python3.6 setup.py install -RUN cd /home/app && cp /usr/local/lib/python3.6/dist-packages/magrit_app-0.3.0-py3.6-linux-x86_64.egg/magrit_app/helpers/*.so /home/app/magrit/magrit_app/helpers/ +RUN cd /home/app && cp /usr/local/lib/python3.6/dist-packages/magrit_app-0.3.1-py3.6-linux-x86_64.egg/magrit_app/helpers/*.so /home/app/magrit/magrit_app/helpers/ EXPOSE 9999 diff --git a/misc/dockerfiles/Dockerfile b/misc/dockerfiles/Dockerfile index 5347757f7..ac8858f89 100644 --- a/misc/dockerfiles/Dockerfile +++ b/misc/dockerfiles/Dockerfile @@ -49,7 +49,7 @@ RUN wget https://bootstrap.pypa.io/get-pip.py && python3.6 get-pip.py RUN cd /home/app/magrit/ \ && pip3.6 install -U -r requirements-dev.txt \ && python3.6 setup.py install -RUN cd /home/app && cp /usr/local/lib/python3.6/dist-packages/magrit_app-0.3.0-py3.6-linux-x86_64.egg/magrit_app/helpers/*.so /home/app/magrit/magrit_app/helpers/ +RUN cd /home/app && cp /usr/local/lib/python3.6/dist-packages/magrit_app-0.3.1-py3.6-linux-x86_64.egg/magrit_app/helpers/*.so /home/app/magrit/magrit_app/helpers/ EXPOSE 9999