root / Ising / Cython / Metropolis.c @ 21
Historique | Voir | Annoter | Télécharger (90,96 ko)
| 1 |
/* Generated by Cython 0.15.1 on Sun May 26 16:17:32 2013 */
|
|---|---|
| 2 |
|
| 3 |
#define PY_SSIZE_T_CLEAN
|
| 4 |
#include "Python.h" |
| 5 |
#ifndef Py_PYTHON_H
|
| 6 |
#error Python headers needed to compile C extensions, please install development version of Python.
|
| 7 |
#else
|
| 8 |
|
| 9 |
#include <stddef.h> /* For offsetof */ |
| 10 |
#ifndef offsetof
|
| 11 |
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) |
| 12 |
#endif
|
| 13 |
|
| 14 |
#if !defined(WIN32) && !defined(MS_WINDOWS)
|
| 15 |
#ifndef __stdcall
|
| 16 |
#define __stdcall
|
| 17 |
#endif
|
| 18 |
#ifndef __cdecl
|
| 19 |
#define __cdecl
|
| 20 |
#endif
|
| 21 |
#ifndef __fastcall
|
| 22 |
#define __fastcall
|
| 23 |
#endif
|
| 24 |
#endif
|
| 25 |
|
| 26 |
#ifndef DL_IMPORT
|
| 27 |
#define DL_IMPORT(t) t
|
| 28 |
#endif
|
| 29 |
#ifndef DL_EXPORT
|
| 30 |
#define DL_EXPORT(t) t
|
| 31 |
#endif
|
| 32 |
|
| 33 |
#ifndef PY_LONG_LONG
|
| 34 |
#define PY_LONG_LONG LONG_LONG
|
| 35 |
#endif
|
| 36 |
|
| 37 |
#if PY_VERSION_HEX < 0x02040000 |
| 38 |
#define METH_COEXIST 0 |
| 39 |
#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
|
| 40 |
#define PyDict_Contains(d,o) PySequence_Contains(d,o)
|
| 41 |
#endif
|
| 42 |
|
| 43 |
#if PY_VERSION_HEX < 0x02050000 |
| 44 |
typedef int Py_ssize_t; |
| 45 |
#define PY_SSIZE_T_MAX INT_MAX
|
| 46 |
#define PY_SSIZE_T_MIN INT_MIN
|
| 47 |
#define PY_FORMAT_SIZE_T "" |
| 48 |
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
|
| 49 |
#define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
|
| 50 |
#define PyNumber_Index(o) PyNumber_Int(o)
|
| 51 |
#define PyIndex_Check(o) PyNumber_Check(o)
|
| 52 |
#define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
|
| 53 |
#endif
|
| 54 |
|
| 55 |
#if PY_VERSION_HEX < 0x02060000 |
| 56 |
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
|
| 57 |
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
|
| 58 |
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
|
| 59 |
#define PyVarObject_HEAD_INIT(type, size) \
|
| 60 |
PyObject_HEAD_INIT(type) size, |
| 61 |
#define PyType_Modified(t)
|
| 62 |
|
| 63 |
typedef struct { |
| 64 |
void *buf;
|
| 65 |
PyObject *obj; |
| 66 |
Py_ssize_t len; |
| 67 |
Py_ssize_t itemsize; |
| 68 |
int readonly;
|
| 69 |
int ndim;
|
| 70 |
char *format;
|
| 71 |
Py_ssize_t *shape; |
| 72 |
Py_ssize_t *strides; |
| 73 |
Py_ssize_t *suboffsets; |
| 74 |
void *internal;
|
| 75 |
} Py_buffer; |
| 76 |
|
| 77 |
#define PyBUF_SIMPLE 0 |
| 78 |
#define PyBUF_WRITABLE 0x0001 |
| 79 |
#define PyBUF_FORMAT 0x0004 |
| 80 |
#define PyBUF_ND 0x0008 |
| 81 |
#define PyBUF_STRIDES (0x0010 | PyBUF_ND) |
| 82 |
#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) |
| 83 |
#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) |
| 84 |
#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) |
| 85 |
#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) |
| 86 |
|
| 87 |
#endif
|
| 88 |
|
| 89 |
#if PY_MAJOR_VERSION < 3 |
| 90 |
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__" |
| 91 |
#else
|
| 92 |
#define __Pyx_BUILTIN_MODULE_NAME "builtins" |
| 93 |
#endif
|
| 94 |
|
| 95 |
#if PY_MAJOR_VERSION >= 3 |
| 96 |
#define Py_TPFLAGS_CHECKTYPES 0 |
| 97 |
#define Py_TPFLAGS_HAVE_INDEX 0 |
| 98 |
#endif
|
| 99 |
|
| 100 |
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) |
| 101 |
#define Py_TPFLAGS_HAVE_NEWBUFFER 0 |
| 102 |
#endif
|
| 103 |
|
| 104 |
#if PY_MAJOR_VERSION >= 3 |
| 105 |
#define PyBaseString_Type PyUnicode_Type
|
| 106 |
#define PyStringObject PyUnicodeObject
|
| 107 |
#define PyString_Type PyUnicode_Type
|
| 108 |
#define PyString_Check PyUnicode_Check
|
| 109 |
#define PyString_CheckExact PyUnicode_CheckExact
|
| 110 |
#endif
|
| 111 |
|
| 112 |
#if PY_VERSION_HEX < 0x02060000 |
| 113 |
#define PyBytesObject PyStringObject
|
| 114 |
#define PyBytes_Type PyString_Type
|
| 115 |
#define PyBytes_Check PyString_Check
|
| 116 |
#define PyBytes_CheckExact PyString_CheckExact
|
| 117 |
#define PyBytes_FromString PyString_FromString
|
| 118 |
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
| 119 |
#define PyBytes_FromFormat PyString_FromFormat
|
| 120 |
#define PyBytes_DecodeEscape PyString_DecodeEscape
|
| 121 |
#define PyBytes_AsString PyString_AsString
|
| 122 |
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
|
| 123 |
#define PyBytes_Size PyString_Size
|
| 124 |
#define PyBytes_AS_STRING PyString_AS_STRING
|
| 125 |
#define PyBytes_GET_SIZE PyString_GET_SIZE
|
| 126 |
#define PyBytes_Repr PyString_Repr
|
| 127 |
#define PyBytes_Concat PyString_Concat
|
| 128 |
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
|
| 129 |
#endif
|
| 130 |
|
| 131 |
#if PY_VERSION_HEX < 0x02060000 |
| 132 |
#define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
|
| 133 |
#define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
|
| 134 |
#endif
|
| 135 |
#ifndef PySet_CheckExact
|
| 136 |
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
|
| 137 |
#endif
|
| 138 |
|
| 139 |
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
|
| 140 |
|
| 141 |
#if PY_MAJOR_VERSION >= 3 |
| 142 |
#define PyIntObject PyLongObject
|
| 143 |
#define PyInt_Type PyLong_Type
|
| 144 |
#define PyInt_Check(op) PyLong_Check(op)
|
| 145 |
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
|
| 146 |
#define PyInt_FromString PyLong_FromString
|
| 147 |
#define PyInt_FromUnicode PyLong_FromUnicode
|
| 148 |
#define PyInt_FromLong PyLong_FromLong
|
| 149 |
#define PyInt_FromSize_t PyLong_FromSize_t
|
| 150 |
#define PyInt_FromSsize_t PyLong_FromSsize_t
|
| 151 |
#define PyInt_AsLong PyLong_AsLong
|
| 152 |
#define PyInt_AS_LONG PyLong_AS_LONG
|
| 153 |
#define PyInt_AsSsize_t PyLong_AsSsize_t
|
| 154 |
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
|
| 155 |
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
|
| 156 |
#endif
|
| 157 |
|
| 158 |
#if PY_MAJOR_VERSION >= 3 |
| 159 |
#define PyBoolObject PyLongObject
|
| 160 |
#endif
|
| 161 |
|
| 162 |
#if PY_VERSION_HEX < 0x03020000 |
| 163 |
typedef long Py_hash_t; |
| 164 |
#define __Pyx_PyInt_FromHash_t PyInt_FromLong
|
| 165 |
#define __Pyx_PyInt_AsHash_t PyInt_AsLong
|
| 166 |
#else
|
| 167 |
#define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
|
| 168 |
#define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
|
| 169 |
#endif
|
| 170 |
|
| 171 |
|
| 172 |
#if PY_MAJOR_VERSION >= 3 |
| 173 |
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
|
| 174 |
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
|
| 175 |
#else
|
| 176 |
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
|
| 177 |
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
|
| 178 |
#endif
|
| 179 |
|
| 180 |
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) |
| 181 |
#define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
|
| 182 |
#define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
|
| 183 |
#define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
|
| 184 |
#else
|
| 185 |
#define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
|
| 186 |
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ |
| 187 |
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ |
| 188 |
(PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) |
| 189 |
#define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
|
| 190 |
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ |
| 191 |
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ |
| 192 |
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) |
| 193 |
#define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
|
| 194 |
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ |
| 195 |
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ |
| 196 |
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) |
| 197 |
#endif
|
| 198 |
|
| 199 |
#if PY_MAJOR_VERSION >= 3 |
| 200 |
#define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
|
| 201 |
#endif
|
| 202 |
|
| 203 |
#if PY_VERSION_HEX < 0x02050000 |
| 204 |
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) |
| 205 |
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) |
| 206 |
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) |
| 207 |
#else
|
| 208 |
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
|
| 209 |
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
|
| 210 |
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
|
| 211 |
#endif
|
| 212 |
|
| 213 |
#if PY_VERSION_HEX < 0x02050000 |
| 214 |
#define __Pyx_NAMESTR(n) ((char *)(n)) |
| 215 |
#define __Pyx_DOCSTR(n) ((char *)(n)) |
| 216 |
#else
|
| 217 |
#define __Pyx_NAMESTR(n) (n)
|
| 218 |
#define __Pyx_DOCSTR(n) (n)
|
| 219 |
#endif
|
| 220 |
|
| 221 |
#ifndef __PYX_EXTERN_C
|
| 222 |
#ifdef __cplusplus
|
| 223 |
#define __PYX_EXTERN_C extern "C" |
| 224 |
#else
|
| 225 |
#define __PYX_EXTERN_C extern |
| 226 |
#endif
|
| 227 |
#endif
|
| 228 |
|
| 229 |
#if defined(WIN32) || defined(MS_WINDOWS)
|
| 230 |
#define _USE_MATH_DEFINES
|
| 231 |
#endif
|
| 232 |
#include <math.h> |
| 233 |
#define __PYX_HAVE__Metropolis
|
| 234 |
#define __PYX_HAVE_API__Metropolis
|
| 235 |
#ifdef _OPENMP
|
| 236 |
#include <omp.h> |
| 237 |
#endif /* _OPENMP */ |
| 238 |
|
| 239 |
#ifdef PYREX_WITHOUT_ASSERTIONS
|
| 240 |
#define CYTHON_WITHOUT_ASSERTIONS
|
| 241 |
#endif
|
| 242 |
|
| 243 |
|
| 244 |
/* inline attribute */
|
| 245 |
#ifndef CYTHON_INLINE
|
| 246 |
#if defined(__GNUC__)
|
| 247 |
#define CYTHON_INLINE __inline__
|
| 248 |
#elif defined(_MSC_VER)
|
| 249 |
#define CYTHON_INLINE __inline
|
| 250 |
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
| 251 |
#define CYTHON_INLINE inline |
| 252 |
#else
|
| 253 |
#define CYTHON_INLINE
|
| 254 |
#endif
|
| 255 |
#endif
|
| 256 |
|
| 257 |
/* unused attribute */
|
| 258 |
#ifndef CYTHON_UNUSED
|
| 259 |
# if defined(__GNUC__)
|
| 260 |
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) |
| 261 |
# define CYTHON_UNUSED __attribute__ ((__unused__))
|
| 262 |
# else
|
| 263 |
# define CYTHON_UNUSED
|
| 264 |
# endif
|
| 265 |
# elif defined(__ICC) || defined(__INTEL_COMPILER)
|
| 266 |
# define CYTHON_UNUSED __attribute__ ((__unused__))
|
| 267 |
# else
|
| 268 |
# define CYTHON_UNUSED
|
| 269 |
# endif
|
| 270 |
#endif
|
| 271 |
|
| 272 |
typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ |
| 273 |
|
| 274 |
|
| 275 |
/* Type Conversion Predeclarations */
|
| 276 |
|
| 277 |
#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) |
| 278 |
#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) |
| 279 |
|
| 280 |
#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
|
| 281 |
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
|
| 282 |
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); |
| 283 |
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
|
| 284 |
|
| 285 |
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
|
| 286 |
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
|
| 287 |
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
|
| 288 |
|
| 289 |
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
|
| 290 |
|
| 291 |
|
| 292 |
#ifdef __GNUC__
|
| 293 |
/* Test for GCC > 2.95 */
|
| 294 |
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 295 |
#define likely(x) __builtin_expect(!!(x), 1) |
| 296 |
#define unlikely(x) __builtin_expect(!!(x), 0) |
| 297 |
#else /* __GNUC__ > 2 ... */ |
| 298 |
#define likely(x) (x)
|
| 299 |
#define unlikely(x) (x)
|
| 300 |
#endif /* __GNUC__ > 2 ... */ |
| 301 |
#else /* __GNUC__ */ |
| 302 |
#define likely(x) (x)
|
| 303 |
#define unlikely(x) (x)
|
| 304 |
#endif /* __GNUC__ */ |
| 305 |
|
| 306 |
static PyObject *__pyx_m;
|
| 307 |
static PyObject *__pyx_b;
|
| 308 |
static PyObject *__pyx_empty_tuple;
|
| 309 |
static PyObject *__pyx_empty_bytes;
|
| 310 |
static int __pyx_lineno; |
| 311 |
static int __pyx_clineno = 0; |
| 312 |
static const char * __pyx_cfilenm= __FILE__; |
| 313 |
static const char *__pyx_filename; |
| 314 |
|
| 315 |
|
| 316 |
static const char *__pyx_f[] = { |
| 317 |
"Metropolis.pyx",
|
| 318 |
}; |
| 319 |
|
| 320 |
/*--- Type declarations ---*/
|
| 321 |
|
| 322 |
#ifndef CYTHON_REFNANNY
|
| 323 |
#define CYTHON_REFNANNY 0 |
| 324 |
#endif
|
| 325 |
|
| 326 |
#if CYTHON_REFNANNY
|
| 327 |
typedef struct { |
| 328 |
void (*INCREF)(void*, PyObject*, int); |
| 329 |
void (*DECREF)(void*, PyObject*, int); |
| 330 |
void (*GOTREF)(void*, PyObject*, int); |
| 331 |
void (*GIVEREF)(void*, PyObject*, int); |
| 332 |
void* (*SetupContext)(const char*, int, const char*); |
| 333 |
void (*FinishContext)(void**); |
| 334 |
} __Pyx_RefNannyAPIStruct; |
| 335 |
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; |
| 336 |
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ |
| 337 |
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; |
| 338 |
#define __Pyx_RefNannySetupContext(name) __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
|
| 339 |
#define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
|
| 340 |
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
|
| 341 |
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
|
| 342 |
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
|
| 343 |
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
|
| 344 |
#define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) |
| 345 |
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) |
| 346 |
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) |
| 347 |
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) |
| 348 |
#else
|
| 349 |
#define __Pyx_RefNannyDeclarations
|
| 350 |
#define __Pyx_RefNannySetupContext(name)
|
| 351 |
#define __Pyx_RefNannyFinishContext()
|
| 352 |
#define __Pyx_INCREF(r) Py_INCREF(r)
|
| 353 |
#define __Pyx_DECREF(r) Py_DECREF(r)
|
| 354 |
#define __Pyx_GOTREF(r)
|
| 355 |
#define __Pyx_GIVEREF(r)
|
| 356 |
#define __Pyx_XINCREF(r) Py_XINCREF(r)
|
| 357 |
#define __Pyx_XDECREF(r) Py_XDECREF(r)
|
| 358 |
#define __Pyx_XGOTREF(r)
|
| 359 |
#define __Pyx_XGIVEREF(r)
|
| 360 |
#endif /* CYTHON_REFNANNY */ |
| 361 |
|
| 362 |
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ |
| 363 |
|
| 364 |
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, |
| 365 |
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
|
| 366 |
|
| 367 |
static void __Pyx_RaiseDoubleKeywordsError( |
| 368 |
const char* func_name, PyObject* kw_name); /*proto*/ |
| 369 |
|
| 370 |
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ |
| 371 |
|
| 372 |
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); |
| 373 |
|
| 374 |
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); |
| 375 |
|
| 376 |
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ |
| 377 |
|
| 378 |
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ |
| 379 |
|
| 380 |
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); |
| 381 |
|
| 382 |
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); |
| 383 |
|
| 384 |
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); |
| 385 |
|
| 386 |
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); |
| 387 |
|
| 388 |
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); |
| 389 |
|
| 390 |
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); |
| 391 |
|
| 392 |
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); |
| 393 |
|
| 394 |
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); |
| 395 |
|
| 396 |
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); |
| 397 |
|
| 398 |
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); |
| 399 |
|
| 400 |
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); |
| 401 |
|
| 402 |
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); |
| 403 |
|
| 404 |
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); |
| 405 |
|
| 406 |
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
|
| 407 |
|
| 408 |
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); |
| 409 |
|
| 410 |
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); |
| 411 |
|
| 412 |
static int __Pyx_check_binary_version(void); |
| 413 |
|
| 414 |
static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno, |
| 415 |
int __pyx_lineno, const char *__pyx_filename); /*proto*/ |
| 416 |
|
| 417 |
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ |
| 418 |
|
| 419 |
/* Module declarations from 'Metropolis' */
|
| 420 |
#define __Pyx_MODULE_NAME "Metropolis" |
| 421 |
int __pyx_module_is_main_Metropolis = 0; |
| 422 |
|
| 423 |
/* Implementation of 'Metropolis' */
|
| 424 |
static PyObject *__pyx_builtin_xrange;
|
| 425 |
static char __pyx_k_1[] = "matplotlib.pyplot"; |
| 426 |
static char __pyx_k_2[] = "*"; |
| 427 |
static char __pyx_k__B[] = "B"; |
| 428 |
static char __pyx_k__J[] = "J"; |
| 429 |
static char __pyx_k__T[] = "T"; |
| 430 |
static char __pyx_k__PIL[] = "PIL"; |
| 431 |
static char __pyx_k__exp[] = "exp"; |
| 432 |
static char __pyx_k__plt[] = "plt"; |
| 433 |
static char __pyx_k__sys[] = "sys"; |
| 434 |
static char __pyx_k__math[] = "math"; |
| 435 |
static char __pyx_k__time[] = "time"; |
| 436 |
static char __pyx_k__Image[] = "Image"; |
| 437 |
static char __pyx_k__numpy[] = "numpy"; |
| 438 |
static char __pyx_k__range[] = "range"; |
| 439 |
static char __pyx_k__shape[] = "shape"; |
| 440 |
static char __pyx_k__sigma[] = "sigma"; |
| 441 |
static char __pyx_k__getopt[] = "getopt"; |
| 442 |
static char __pyx_k__random[] = "random"; |
| 443 |
static char __pyx_k__xrange[] = "xrange"; |
| 444 |
static char __pyx_k__randint[] = "randint"; |
| 445 |
static char __pyx_k____main__[] = "__main__"; |
| 446 |
static char __pyx_k____test__[] = "__test__"; |
| 447 |
static char __pyx_k__Metropolis[] = "Metropolis"; |
| 448 |
static char __pyx_k__iterations[] = "iterations"; |
| 449 |
static PyObject *__pyx_n_s_1;
|
| 450 |
static PyObject *__pyx_n_s_2;
|
| 451 |
static PyObject *__pyx_n_s__B;
|
| 452 |
static PyObject *__pyx_n_s__Image;
|
| 453 |
static PyObject *__pyx_n_s__J;
|
| 454 |
static PyObject *__pyx_n_s__Metropolis;
|
| 455 |
static PyObject *__pyx_n_s__PIL;
|
| 456 |
static PyObject *__pyx_n_s__T;
|
| 457 |
static PyObject *__pyx_n_s____main__;
|
| 458 |
static PyObject *__pyx_n_s____test__;
|
| 459 |
static PyObject *__pyx_n_s__exp;
|
| 460 |
static PyObject *__pyx_n_s__getopt;
|
| 461 |
static PyObject *__pyx_n_s__iterations;
|
| 462 |
static PyObject *__pyx_n_s__math;
|
| 463 |
static PyObject *__pyx_n_s__numpy;
|
| 464 |
static PyObject *__pyx_n_s__plt;
|
| 465 |
static PyObject *__pyx_n_s__randint;
|
| 466 |
static PyObject *__pyx_n_s__random;
|
| 467 |
static PyObject *__pyx_n_s__range;
|
| 468 |
static PyObject *__pyx_n_s__shape;
|
| 469 |
static PyObject *__pyx_n_s__sigma;
|
| 470 |
static PyObject *__pyx_n_s__sys;
|
| 471 |
static PyObject *__pyx_n_s__time;
|
| 472 |
static PyObject *__pyx_n_s__xrange;
|
| 473 |
static PyObject *__pyx_int_0;
|
| 474 |
static PyObject *__pyx_int_1;
|
| 475 |
static PyObject *__pyx_int_2;
|
| 476 |
|
| 477 |
/* "Metropolis.pyx":17
|
| 478 |
* import Metropolis
|
| 479 |
*
|
| 480 |
* def Metropolis(sigma,J,B,T,iterations): # <<<<<<<<<<<<<<
|
| 481 |
* start=time.time()
|
| 482 |
*
|
| 483 |
*/
|
| 484 |
|
| 485 |
static PyObject *__pyx_pf_10Metropolis_Metropolis(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ |
| 486 |
static PyMethodDef __pyx_mdef_10Metropolis_Metropolis = {__Pyx_NAMESTR("Metropolis"), (PyCFunction)__pyx_pf_10Metropolis_Metropolis, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; |
| 487 |
static PyObject *__pyx_pf_10Metropolis_Metropolis(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
|
| 488 |
PyObject *__pyx_v_sigma = 0;
|
| 489 |
PyObject *__pyx_v_J = 0;
|
| 490 |
PyObject *__pyx_v_B = 0;
|
| 491 |
PyObject *__pyx_v_T = 0;
|
| 492 |
PyObject *__pyx_v_iterations = 0;
|
| 493 |
PyObject *__pyx_v_start = NULL;
|
| 494 |
PyObject *__pyx_v_SizeX = NULL;
|
| 495 |
PyObject *__pyx_v_SizeY = NULL;
|
| 496 |
PyObject *__pyx_v_p = NULL;
|
| 497 |
PyObject *__pyx_v_X = NULL;
|
| 498 |
PyObject *__pyx_v_Y = NULL;
|
| 499 |
PyObject *__pyx_v_DeltaE = NULL;
|
| 500 |
PyObject *__pyx_v_duration = NULL;
|
| 501 |
PyObject *__pyx_r = NULL;
|
| 502 |
__Pyx_RefNannyDeclarations |
| 503 |
PyObject *__pyx_t_1 = NULL;
|
| 504 |
PyObject *__pyx_t_2 = NULL;
|
| 505 |
PyObject *__pyx_t_3 = NULL;
|
| 506 |
PyObject *__pyx_t_4 = NULL;
|
| 507 |
PyObject *(*__pyx_t_5)(PyObject *); |
| 508 |
Py_ssize_t __pyx_t_6; |
| 509 |
PyObject *(*__pyx_t_7)(PyObject *); |
| 510 |
PyObject *__pyx_t_8 = NULL;
|
| 511 |
int __pyx_t_9;
|
| 512 |
int __pyx_t_10;
|
| 513 |
int __pyx_t_11;
|
| 514 |
int __pyx_lineno = 0; |
| 515 |
const char *__pyx_filename = NULL; |
| 516 |
int __pyx_clineno = 0; |
| 517 |
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sigma,&__pyx_n_s__J,&__pyx_n_s__B,&__pyx_n_s__T,&__pyx_n_s__iterations,0}; |
| 518 |
__Pyx_RefNannySetupContext("Metropolis");
|
| 519 |
__pyx_self = __pyx_self; |
| 520 |
{
|
| 521 |
PyObject* values[5] = {0,0,0,0,0}; |
| 522 |
if (unlikely(__pyx_kwds)) {
|
| 523 |
Py_ssize_t kw_args; |
| 524 |
switch (PyTuple_GET_SIZE(__pyx_args)) {
|
| 525 |
case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); |
| 526 |
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); |
| 527 |
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); |
| 528 |
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); |
| 529 |
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); |
| 530 |
case 0: break; |
| 531 |
default: goto __pyx_L5_argtuple_error; |
| 532 |
} |
| 533 |
kw_args = PyDict_Size(__pyx_kwds); |
| 534 |
switch (PyTuple_GET_SIZE(__pyx_args)) {
|
| 535 |
case 0: |
| 536 |
values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sigma);
|
| 537 |
if (likely(values[0])) kw_args--; |
| 538 |
else goto __pyx_L5_argtuple_error; |
| 539 |
case 1: |
| 540 |
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__J);
|
| 541 |
if (likely(values[1])) kw_args--; |
| 542 |
else {
|
| 543 |
__Pyx_RaiseArgtupleInvalid("Metropolis", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 544 |
} |
| 545 |
case 2: |
| 546 |
values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B);
|
| 547 |
if (likely(values[2])) kw_args--; |
| 548 |
else {
|
| 549 |
__Pyx_RaiseArgtupleInvalid("Metropolis", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 550 |
} |
| 551 |
case 3: |
| 552 |
values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T);
|
| 553 |
if (likely(values[3])) kw_args--; |
| 554 |
else {
|
| 555 |
__Pyx_RaiseArgtupleInvalid("Metropolis", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 556 |
} |
| 557 |
case 4: |
| 558 |
values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__iterations);
|
| 559 |
if (likely(values[4])) kw_args--; |
| 560 |
else {
|
| 561 |
__Pyx_RaiseArgtupleInvalid("Metropolis", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 562 |
} |
| 563 |
} |
| 564 |
if (unlikely(kw_args > 0)) { |
| 565 |
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "Metropolis") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 566 |
} |
| 567 |
} else if (PyTuple_GET_SIZE(__pyx_args) != 5) { |
| 568 |
goto __pyx_L5_argtuple_error;
|
| 569 |
} else {
|
| 570 |
values[0] = PyTuple_GET_ITEM(__pyx_args, 0); |
| 571 |
values[1] = PyTuple_GET_ITEM(__pyx_args, 1); |
| 572 |
values[2] = PyTuple_GET_ITEM(__pyx_args, 2); |
| 573 |
values[3] = PyTuple_GET_ITEM(__pyx_args, 3); |
| 574 |
values[4] = PyTuple_GET_ITEM(__pyx_args, 4); |
| 575 |
} |
| 576 |
__pyx_v_sigma = values[0];
|
| 577 |
__pyx_v_J = values[1];
|
| 578 |
__pyx_v_B = values[2];
|
| 579 |
__pyx_v_T = values[3];
|
| 580 |
__pyx_v_iterations = values[4];
|
| 581 |
} |
| 582 |
goto __pyx_L4_argument_unpacking_done;
|
| 583 |
__pyx_L5_argtuple_error:;
|
| 584 |
__Pyx_RaiseArgtupleInvalid("Metropolis", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} |
| 585 |
__pyx_L3_error:;
|
| 586 |
__Pyx_AddTraceback("Metropolis.Metropolis", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
| 587 |
__Pyx_RefNannyFinishContext(); |
| 588 |
return NULL; |
| 589 |
__pyx_L4_argument_unpacking_done:;
|
| 590 |
|
| 591 |
/* "Metropolis.pyx":18
|
| 592 |
*
|
| 593 |
* def Metropolis(sigma,J,B,T,iterations):
|
| 594 |
* start=time.time() # <<<<<<<<<<<<<<
|
| 595 |
*
|
| 596 |
* SizeX,SizeY=sigma.shape
|
| 597 |
*/
|
| 598 |
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 599 |
__Pyx_GOTREF(__pyx_t_1); |
| 600 |
__pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__time); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 601 |
__Pyx_GOTREF(__pyx_t_2); |
| 602 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 603 |
__pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 604 |
__Pyx_GOTREF(__pyx_t_1); |
| 605 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 606 |
__pyx_v_start = __pyx_t_1; |
| 607 |
__pyx_t_1 = 0;
|
| 608 |
|
| 609 |
/* "Metropolis.pyx":20
|
| 610 |
* start=time.time()
|
| 611 |
*
|
| 612 |
* SizeX,SizeY=sigma.shape # <<<<<<<<<<<<<<
|
| 613 |
*
|
| 614 |
* for p in xrange(0,iterations):
|
| 615 |
*/
|
| 616 |
__pyx_t_1 = PyObject_GetAttr(__pyx_v_sigma, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 617 |
__Pyx_GOTREF(__pyx_t_1); |
| 618 |
if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
|
| 619 |
PyObject* sequence = __pyx_t_1; |
| 620 |
if (likely(PyTuple_CheckExact(sequence))) {
|
| 621 |
if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) { |
| 622 |
if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); |
| 623 |
else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
|
| 624 |
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
| 625 |
} |
| 626 |
__pyx_t_2 = PyTuple_GET_ITEM(sequence, 0);
|
| 627 |
__pyx_t_3 = PyTuple_GET_ITEM(sequence, 1);
|
| 628 |
} else {
|
| 629 |
if (unlikely(PyList_GET_SIZE(sequence) != 2)) { |
| 630 |
if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); |
| 631 |
else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
|
| 632 |
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
| 633 |
} |
| 634 |
__pyx_t_2 = PyList_GET_ITEM(sequence, 0);
|
| 635 |
__pyx_t_3 = PyList_GET_ITEM(sequence, 1);
|
| 636 |
} |
| 637 |
__Pyx_INCREF(__pyx_t_2); |
| 638 |
__Pyx_INCREF(__pyx_t_3); |
| 639 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 640 |
} else {
|
| 641 |
Py_ssize_t index = -1;
|
| 642 |
__pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 643 |
__Pyx_GOTREF(__pyx_t_4); |
| 644 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 645 |
__pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; |
| 646 |
index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed; |
| 647 |
__Pyx_GOTREF(__pyx_t_2); |
| 648 |
index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; |
| 649 |
__Pyx_GOTREF(__pyx_t_3); |
| 650 |
if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 651 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 652 |
goto __pyx_L7_unpacking_done;
|
| 653 |
__pyx_L6_unpacking_failed:;
|
| 654 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 655 |
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
|
| 656 |
if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
|
| 657 |
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
|
| 658 |
__pyx_L7_unpacking_done:;
|
| 659 |
} |
| 660 |
__pyx_v_SizeX = __pyx_t_2; |
| 661 |
__pyx_t_2 = 0;
|
| 662 |
__pyx_v_SizeY = __pyx_t_3; |
| 663 |
__pyx_t_3 = 0;
|
| 664 |
|
| 665 |
/* "Metropolis.pyx":22
|
| 666 |
* SizeX,SizeY=sigma.shape
|
| 667 |
*
|
| 668 |
* for p in xrange(0,iterations): # <<<<<<<<<<<<<<
|
| 669 |
* # Random access coordonate
|
| 670 |
* X,Y=numpy.random.randint(SizeX),numpy.random.randint(SizeY)
|
| 671 |
*/
|
| 672 |
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 673 |
__Pyx_GOTREF(((PyObject *)__pyx_t_1)); |
| 674 |
__Pyx_INCREF(__pyx_int_0); |
| 675 |
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
|
| 676 |
__Pyx_GIVEREF(__pyx_int_0); |
| 677 |
__Pyx_INCREF(__pyx_v_iterations); |
| 678 |
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_iterations);
|
| 679 |
__Pyx_GIVEREF(__pyx_v_iterations); |
| 680 |
__pyx_t_3 = PyObject_Call(__pyx_builtin_xrange, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 681 |
__Pyx_GOTREF(__pyx_t_3); |
| 682 |
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
|
| 683 |
if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) {
|
| 684 |
__pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
|
| 685 |
__pyx_t_7 = NULL;
|
| 686 |
} else {
|
| 687 |
__pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 688 |
__Pyx_GOTREF(__pyx_t_1); |
| 689 |
__pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; |
| 690 |
} |
| 691 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 692 |
for (;;) {
|
| 693 |
if (PyList_CheckExact(__pyx_t_1)) {
|
| 694 |
if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; |
| 695 |
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; |
| 696 |
} else if (PyTuple_CheckExact(__pyx_t_1)) { |
| 697 |
if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break; |
| 698 |
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; |
| 699 |
} else {
|
| 700 |
__pyx_t_3 = __pyx_t_7(__pyx_t_1); |
| 701 |
if (unlikely(!__pyx_t_3)) {
|
| 702 |
if (PyErr_Occurred()) {
|
| 703 |
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
|
| 704 |
else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 705 |
} |
| 706 |
break;
|
| 707 |
} |
| 708 |
__Pyx_GOTREF(__pyx_t_3); |
| 709 |
} |
| 710 |
__Pyx_XDECREF(__pyx_v_p); |
| 711 |
__pyx_v_p = __pyx_t_3; |
| 712 |
__pyx_t_3 = 0;
|
| 713 |
|
| 714 |
/* "Metropolis.pyx":24
|
| 715 |
* for p in xrange(0,iterations):
|
| 716 |
* # Random access coordonate
|
| 717 |
* X,Y=numpy.random.randint(SizeX),numpy.random.randint(SizeY) # <<<<<<<<<<<<<<
|
| 718 |
*
|
| 719 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+
|
| 720 |
*/
|
| 721 |
__pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 722 |
__Pyx_GOTREF(__pyx_t_3); |
| 723 |
__pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__random); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 724 |
__Pyx_GOTREF(__pyx_t_2); |
| 725 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 726 |
__pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__randint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 727 |
__Pyx_GOTREF(__pyx_t_3); |
| 728 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 729 |
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 730 |
__Pyx_GOTREF(((PyObject *)__pyx_t_2)); |
| 731 |
__Pyx_INCREF(__pyx_v_SizeX); |
| 732 |
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_SizeX);
|
| 733 |
__Pyx_GIVEREF(__pyx_v_SizeX); |
| 734 |
__pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 735 |
__Pyx_GOTREF(__pyx_t_4); |
| 736 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 737 |
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
|
| 738 |
__pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 739 |
__Pyx_GOTREF(__pyx_t_2); |
| 740 |
__pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 741 |
__Pyx_GOTREF(__pyx_t_3); |
| 742 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 743 |
__pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__randint); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 744 |
__Pyx_GOTREF(__pyx_t_2); |
| 745 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 746 |
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 747 |
__Pyx_GOTREF(((PyObject *)__pyx_t_3)); |
| 748 |
__Pyx_INCREF(__pyx_v_SizeY); |
| 749 |
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_SizeY);
|
| 750 |
__Pyx_GIVEREF(__pyx_v_SizeY); |
| 751 |
__pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 752 |
__Pyx_GOTREF(__pyx_t_8); |
| 753 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 754 |
__Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
|
| 755 |
__Pyx_XDECREF(__pyx_v_X); |
| 756 |
__pyx_v_X = __pyx_t_4; |
| 757 |
__pyx_t_4 = 0;
|
| 758 |
__Pyx_XDECREF(__pyx_v_Y); |
| 759 |
__pyx_v_Y = __pyx_t_8; |
| 760 |
__pyx_t_8 = 0;
|
| 761 |
|
| 762 |
/* "Metropolis.pyx":26
|
| 763 |
* X,Y=numpy.random.randint(SizeX),numpy.random.randint(SizeY)
|
| 764 |
*
|
| 765 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+ # <<<<<<<<<<<<<<
|
| 766 |
* sigma[X,(Y-1)%SizeY]+
|
| 767 |
* sigma[(X-1)%SizeX,Y]+
|
| 768 |
*/
|
| 769 |
__pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 770 |
__Pyx_GOTREF(((PyObject *)__pyx_t_8)); |
| 771 |
__Pyx_INCREF(__pyx_v_X); |
| 772 |
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_X);
|
| 773 |
__Pyx_GIVEREF(__pyx_v_X); |
| 774 |
__Pyx_INCREF(__pyx_v_Y); |
| 775 |
PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_Y);
|
| 776 |
__Pyx_GIVEREF(__pyx_v_Y); |
| 777 |
__pyx_t_4 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_8)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 778 |
__Pyx_GOTREF(__pyx_t_4); |
| 779 |
__Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
|
| 780 |
__pyx_t_8 = PyNumber_Multiply(__pyx_v_J, __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 781 |
__Pyx_GOTREF(__pyx_t_8); |
| 782 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 783 |
|
| 784 |
/* "Metropolis.pyx":27
|
| 785 |
*
|
| 786 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+
|
| 787 |
* sigma[X,(Y-1)%SizeY]+ # <<<<<<<<<<<<<<
|
| 788 |
* sigma[(X-1)%SizeX,Y]+
|
| 789 |
* sigma[(X+1)%SizeX,Y])+B)
|
| 790 |
*/
|
| 791 |
__pyx_t_4 = PyNumber_Add(__pyx_v_Y, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 792 |
__Pyx_GOTREF(__pyx_t_4); |
| 793 |
|
| 794 |
/* "Metropolis.pyx":26
|
| 795 |
* X,Y=numpy.random.randint(SizeX),numpy.random.randint(SizeY)
|
| 796 |
*
|
| 797 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+ # <<<<<<<<<<<<<<
|
| 798 |
* sigma[X,(Y-1)%SizeY]+
|
| 799 |
* sigma[(X-1)%SizeX,Y]+
|
| 800 |
*/
|
| 801 |
__pyx_t_3 = PyNumber_Remainder(__pyx_t_4, __pyx_v_SizeY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 802 |
__Pyx_GOTREF(__pyx_t_3); |
| 803 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 804 |
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 805 |
__Pyx_GOTREF(((PyObject *)__pyx_t_4)); |
| 806 |
__Pyx_INCREF(__pyx_v_X); |
| 807 |
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_X);
|
| 808 |
__Pyx_GIVEREF(__pyx_v_X); |
| 809 |
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
|
| 810 |
__Pyx_GIVEREF(__pyx_t_3); |
| 811 |
__pyx_t_3 = 0;
|
| 812 |
__pyx_t_3 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_4)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 813 |
__Pyx_GOTREF(__pyx_t_3); |
| 814 |
__Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
|
| 815 |
|
| 816 |
/* "Metropolis.pyx":27
|
| 817 |
*
|
| 818 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+
|
| 819 |
* sigma[X,(Y-1)%SizeY]+ # <<<<<<<<<<<<<<
|
| 820 |
* sigma[(X-1)%SizeX,Y]+
|
| 821 |
* sigma[(X+1)%SizeX,Y])+B)
|
| 822 |
*/
|
| 823 |
__pyx_t_4 = PyNumber_Subtract(__pyx_v_Y, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 824 |
__Pyx_GOTREF(__pyx_t_4); |
| 825 |
__pyx_t_2 = PyNumber_Remainder(__pyx_t_4, __pyx_v_SizeY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 826 |
__Pyx_GOTREF(__pyx_t_2); |
| 827 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 828 |
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 829 |
__Pyx_GOTREF(((PyObject *)__pyx_t_4)); |
| 830 |
__Pyx_INCREF(__pyx_v_X); |
| 831 |
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_X);
|
| 832 |
__Pyx_GIVEREF(__pyx_v_X); |
| 833 |
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
|
| 834 |
__Pyx_GIVEREF(__pyx_t_2); |
| 835 |
__pyx_t_2 = 0;
|
| 836 |
__pyx_t_2 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_4)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 837 |
__Pyx_GOTREF(__pyx_t_2); |
| 838 |
__Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
|
| 839 |
__pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 840 |
__Pyx_GOTREF(__pyx_t_4); |
| 841 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 842 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 843 |
|
| 844 |
/* "Metropolis.pyx":28
|
| 845 |
* DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+
|
| 846 |
* sigma[X,(Y-1)%SizeY]+
|
| 847 |
* sigma[(X-1)%SizeX,Y]+ # <<<<<<<<<<<<<<
|
| 848 |
* sigma[(X+1)%SizeX,Y])+B)
|
| 849 |
*
|
| 850 |
*/
|
| 851 |
__pyx_t_2 = PyNumber_Subtract(__pyx_v_X, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 852 |
__Pyx_GOTREF(__pyx_t_2); |
| 853 |
__pyx_t_3 = PyNumber_Remainder(__pyx_t_2, __pyx_v_SizeX); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 854 |
__Pyx_GOTREF(__pyx_t_3); |
| 855 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 856 |
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 857 |
__Pyx_GOTREF(((PyObject *)__pyx_t_2)); |
| 858 |
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
|
| 859 |
__Pyx_GIVEREF(__pyx_t_3); |
| 860 |
__Pyx_INCREF(__pyx_v_Y); |
| 861 |
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_Y);
|
| 862 |
__Pyx_GIVEREF(__pyx_v_Y); |
| 863 |
__pyx_t_3 = 0;
|
| 864 |
__pyx_t_3 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_2)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 865 |
__Pyx_GOTREF(__pyx_t_3); |
| 866 |
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
|
| 867 |
__pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 868 |
__Pyx_GOTREF(__pyx_t_2); |
| 869 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 870 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 871 |
|
| 872 |
/* "Metropolis.pyx":29
|
| 873 |
* sigma[X,(Y-1)%SizeY]+
|
| 874 |
* sigma[(X-1)%SizeX,Y]+
|
| 875 |
* sigma[(X+1)%SizeX,Y])+B) # <<<<<<<<<<<<<<
|
| 876 |
*
|
| 877 |
* if DeltaE < 0. or random() < exp(-DeltaE/T):
|
| 878 |
*/
|
| 879 |
__pyx_t_3 = PyNumber_Add(__pyx_v_X, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 880 |
__Pyx_GOTREF(__pyx_t_3); |
| 881 |
__pyx_t_4 = PyNumber_Remainder(__pyx_t_3, __pyx_v_SizeX); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 882 |
__Pyx_GOTREF(__pyx_t_4); |
| 883 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 884 |
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 885 |
__Pyx_GOTREF(((PyObject *)__pyx_t_3)); |
| 886 |
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
|
| 887 |
__Pyx_GIVEREF(__pyx_t_4); |
| 888 |
__Pyx_INCREF(__pyx_v_Y); |
| 889 |
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_Y);
|
| 890 |
__Pyx_GIVEREF(__pyx_v_Y); |
| 891 |
__pyx_t_4 = 0;
|
| 892 |
__pyx_t_4 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_3)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 893 |
__Pyx_GOTREF(__pyx_t_4); |
| 894 |
__Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
|
| 895 |
__pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 896 |
__Pyx_GOTREF(__pyx_t_3); |
| 897 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 898 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 899 |
__pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 900 |
__Pyx_GOTREF(__pyx_t_4); |
| 901 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 902 |
__pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_v_B); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 903 |
__Pyx_GOTREF(__pyx_t_3); |
| 904 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 905 |
__pyx_t_4 = PyNumber_Multiply(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 906 |
__Pyx_GOTREF(__pyx_t_4); |
| 907 |
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
|
| 908 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 909 |
__Pyx_XDECREF(__pyx_v_DeltaE); |
| 910 |
__pyx_v_DeltaE = __pyx_t_4; |
| 911 |
__pyx_t_4 = 0;
|
| 912 |
|
| 913 |
/* "Metropolis.pyx":31
|
| 914 |
* sigma[(X+1)%SizeX,Y])+B)
|
| 915 |
*
|
| 916 |
* if DeltaE < 0. or random() < exp(-DeltaE/T): # <<<<<<<<<<<<<<
|
| 917 |
* sigma[X,Y]=-sigma[X,Y]
|
| 918 |
* duration=time.time()-start
|
| 919 |
*/
|
| 920 |
__pyx_t_4 = PyFloat_FromDouble(0.); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 921 |
__Pyx_GOTREF(__pyx_t_4); |
| 922 |
__pyx_t_3 = PyObject_RichCompare(__pyx_v_DeltaE, __pyx_t_4, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 923 |
__Pyx_GOTREF(__pyx_t_3); |
| 924 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 925 |
__pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 926 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 927 |
if (!__pyx_t_9) {
|
| 928 |
__pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__random); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 929 |
__Pyx_GOTREF(__pyx_t_3); |
| 930 |
__pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 931 |
__Pyx_GOTREF(__pyx_t_4); |
| 932 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 933 |
__pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__exp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 934 |
__Pyx_GOTREF(__pyx_t_3); |
| 935 |
__pyx_t_8 = PyNumber_Negative(__pyx_v_DeltaE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 936 |
__Pyx_GOTREF(__pyx_t_8); |
| 937 |
__pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_8, __pyx_v_T); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 938 |
__Pyx_GOTREF(__pyx_t_2); |
| 939 |
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
|
| 940 |
__pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 941 |
__Pyx_GOTREF(((PyObject *)__pyx_t_8)); |
| 942 |
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
|
| 943 |
__Pyx_GIVEREF(__pyx_t_2); |
| 944 |
__pyx_t_2 = 0;
|
| 945 |
__pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 946 |
__Pyx_GOTREF(__pyx_t_2); |
| 947 |
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
|
| 948 |
__Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
|
| 949 |
__pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 950 |
__Pyx_GOTREF(__pyx_t_8); |
| 951 |
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
|
| 952 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 953 |
__pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 954 |
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
|
| 955 |
__pyx_t_11 = __pyx_t_10; |
| 956 |
} else {
|
| 957 |
__pyx_t_11 = __pyx_t_9; |
| 958 |
} |
| 959 |
if (__pyx_t_11) {
|
| 960 |
|
| 961 |
/* "Metropolis.pyx":32
|
| 962 |
*
|
| 963 |
* if DeltaE < 0. or random() < exp(-DeltaE/T):
|
| 964 |
* sigma[X,Y]=-sigma[X,Y] # <<<<<<<<<<<<<<
|
| 965 |
* duration=time.time()-start
|
| 966 |
* return(duration)
|
| 967 |
*/
|
| 968 |
__pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 969 |
__Pyx_GOTREF(((PyObject *)__pyx_t_8)); |
| 970 |
__Pyx_INCREF(__pyx_v_X); |
| 971 |
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_X);
|
| 972 |
__Pyx_GIVEREF(__pyx_v_X); |
| 973 |
__Pyx_INCREF(__pyx_v_Y); |
| 974 |
PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_Y);
|
| 975 |
__Pyx_GIVEREF(__pyx_v_Y); |
| 976 |
__pyx_t_2 = PyObject_GetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_8)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 977 |
__Pyx_GOTREF(__pyx_t_2); |
| 978 |
__Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
|
| 979 |
__pyx_t_8 = PyNumber_Negative(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 980 |
__Pyx_GOTREF(__pyx_t_8); |
| 981 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 982 |
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 983 |
__Pyx_GOTREF(((PyObject *)__pyx_t_2)); |
| 984 |
__Pyx_INCREF(__pyx_v_X); |
| 985 |
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_X);
|
| 986 |
__Pyx_GIVEREF(__pyx_v_X); |
| 987 |
__Pyx_INCREF(__pyx_v_Y); |
| 988 |
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_Y);
|
| 989 |
__Pyx_GIVEREF(__pyx_v_Y); |
| 990 |
if (PyObject_SetItem(__pyx_v_sigma, ((PyObject *)__pyx_t_2), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 991 |
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
|
| 992 |
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
|
| 993 |
goto __pyx_L10;
|
| 994 |
} |
| 995 |
__pyx_L10:;
|
| 996 |
} |
| 997 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 998 |
|
| 999 |
/* "Metropolis.pyx":33
|
| 1000 |
* if DeltaE < 0. or random() < exp(-DeltaE/T):
|
| 1001 |
* sigma[X,Y]=-sigma[X,Y]
|
| 1002 |
* duration=time.time()-start # <<<<<<<<<<<<<<
|
| 1003 |
* return(duration)
|
| 1004 |
*/
|
| 1005 |
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1006 |
__Pyx_GOTREF(__pyx_t_1); |
| 1007 |
__pyx_t_8 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__time); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1008 |
__Pyx_GOTREF(__pyx_t_8); |
| 1009 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1010 |
__pyx_t_1 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1011 |
__Pyx_GOTREF(__pyx_t_1); |
| 1012 |
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
|
| 1013 |
__pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_v_start); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1014 |
__Pyx_GOTREF(__pyx_t_8); |
| 1015 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1016 |
__pyx_v_duration = __pyx_t_8; |
| 1017 |
__pyx_t_8 = 0;
|
| 1018 |
|
| 1019 |
/* "Metropolis.pyx":34
|
| 1020 |
* sigma[X,Y]=-sigma[X,Y]
|
| 1021 |
* duration=time.time()-start
|
| 1022 |
* return(duration) # <<<<<<<<<<<<<<
|
| 1023 |
*/
|
| 1024 |
__Pyx_XDECREF(__pyx_r); |
| 1025 |
__Pyx_INCREF(__pyx_v_duration); |
| 1026 |
__pyx_r = __pyx_v_duration; |
| 1027 |
goto __pyx_L0;
|
| 1028 |
|
| 1029 |
__pyx_r = Py_None; __Pyx_INCREF(Py_None); |
| 1030 |
goto __pyx_L0;
|
| 1031 |
__pyx_L1_error:;
|
| 1032 |
__Pyx_XDECREF(__pyx_t_1); |
| 1033 |
__Pyx_XDECREF(__pyx_t_2); |
| 1034 |
__Pyx_XDECREF(__pyx_t_3); |
| 1035 |
__Pyx_XDECREF(__pyx_t_4); |
| 1036 |
__Pyx_XDECREF(__pyx_t_8); |
| 1037 |
__Pyx_AddTraceback("Metropolis.Metropolis", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
| 1038 |
__pyx_r = NULL;
|
| 1039 |
__pyx_L0:;
|
| 1040 |
__Pyx_XDECREF(__pyx_v_start); |
| 1041 |
__Pyx_XDECREF(__pyx_v_SizeX); |
| 1042 |
__Pyx_XDECREF(__pyx_v_SizeY); |
| 1043 |
__Pyx_XDECREF(__pyx_v_p); |
| 1044 |
__Pyx_XDECREF(__pyx_v_X); |
| 1045 |
__Pyx_XDECREF(__pyx_v_Y); |
| 1046 |
__Pyx_XDECREF(__pyx_v_DeltaE); |
| 1047 |
__Pyx_XDECREF(__pyx_v_duration); |
| 1048 |
__Pyx_XGIVEREF(__pyx_r); |
| 1049 |
__Pyx_RefNannyFinishContext(); |
| 1050 |
return __pyx_r;
|
| 1051 |
} |
| 1052 |
|
| 1053 |
static PyMethodDef __pyx_methods[] = {
|
| 1054 |
{0, 0, 0, 0}
|
| 1055 |
}; |
| 1056 |
|
| 1057 |
#if PY_MAJOR_VERSION >= 3 |
| 1058 |
static struct PyModuleDef __pyx_moduledef = { |
| 1059 |
PyModuleDef_HEAD_INIT, |
| 1060 |
__Pyx_NAMESTR("Metropolis"),
|
| 1061 |
0, /* m_doc */ |
| 1062 |
-1, /* m_size */ |
| 1063 |
__pyx_methods /* m_methods */,
|
| 1064 |
NULL, /* m_reload */ |
| 1065 |
NULL, /* m_traverse */ |
| 1066 |
NULL, /* m_clear */ |
| 1067 |
NULL /* m_free */ |
| 1068 |
}; |
| 1069 |
#endif
|
| 1070 |
|
| 1071 |
static __Pyx_StringTabEntry __pyx_string_tab[] = {
|
| 1072 |
{&__pyx_n_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 1},
|
| 1073 |
{&__pyx_n_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 1},
|
| 1074 |
{&__pyx_n_s__B, __pyx_k__B, sizeof(__pyx_k__B), 0, 0, 1, 1},
|
| 1075 |
{&__pyx_n_s__Image, __pyx_k__Image, sizeof(__pyx_k__Image), 0, 0, 1, 1},
|
| 1076 |
{&__pyx_n_s__J, __pyx_k__J, sizeof(__pyx_k__J), 0, 0, 1, 1},
|
| 1077 |
{&__pyx_n_s__Metropolis, __pyx_k__Metropolis, sizeof(__pyx_k__Metropolis), 0, 0, 1, 1},
|
| 1078 |
{&__pyx_n_s__PIL, __pyx_k__PIL, sizeof(__pyx_k__PIL), 0, 0, 1, 1},
|
| 1079 |
{&__pyx_n_s__T, __pyx_k__T, sizeof(__pyx_k__T), 0, 0, 1, 1},
|
| 1080 |
{&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
|
| 1081 |
{&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
|
| 1082 |
{&__pyx_n_s__exp, __pyx_k__exp, sizeof(__pyx_k__exp), 0, 0, 1, 1},
|
| 1083 |
{&__pyx_n_s__getopt, __pyx_k__getopt, sizeof(__pyx_k__getopt), 0, 0, 1, 1},
|
| 1084 |
{&__pyx_n_s__iterations, __pyx_k__iterations, sizeof(__pyx_k__iterations), 0, 0, 1, 1},
|
| 1085 |
{&__pyx_n_s__math, __pyx_k__math, sizeof(__pyx_k__math), 0, 0, 1, 1},
|
| 1086 |
{&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1},
|
| 1087 |
{&__pyx_n_s__plt, __pyx_k__plt, sizeof(__pyx_k__plt), 0, 0, 1, 1},
|
| 1088 |
{&__pyx_n_s__randint, __pyx_k__randint, sizeof(__pyx_k__randint), 0, 0, 1, 1},
|
| 1089 |
{&__pyx_n_s__random, __pyx_k__random, sizeof(__pyx_k__random), 0, 0, 1, 1},
|
| 1090 |
{&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
|
| 1091 |
{&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1},
|
| 1092 |
{&__pyx_n_s__sigma, __pyx_k__sigma, sizeof(__pyx_k__sigma), 0, 0, 1, 1},
|
| 1093 |
{&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
|
| 1094 |
{&__pyx_n_s__time, __pyx_k__time, sizeof(__pyx_k__time), 0, 0, 1, 1},
|
| 1095 |
{&__pyx_n_s__xrange, __pyx_k__xrange, sizeof(__pyx_k__xrange), 0, 0, 1, 1},
|
| 1096 |
{0, 0, 0, 0, 0, 0, 0}
|
| 1097 |
}; |
| 1098 |
static int __Pyx_InitCachedBuiltins(void) { |
| 1099 |
#if PY_MAJOR_VERSION >= 3 |
| 1100 |
__pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1101 |
#else
|
| 1102 |
__pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1103 |
#endif
|
| 1104 |
return 0; |
| 1105 |
__pyx_L1_error:;
|
| 1106 |
return -1; |
| 1107 |
} |
| 1108 |
|
| 1109 |
static int __Pyx_InitCachedConstants(void) { |
| 1110 |
__Pyx_RefNannyDeclarations |
| 1111 |
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
|
| 1112 |
__Pyx_RefNannyFinishContext(); |
| 1113 |
return 0; |
| 1114 |
} |
| 1115 |
|
| 1116 |
static int __Pyx_InitGlobals(void) { |
| 1117 |
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; |
| 1118 |
__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;}; |
| 1119 |
__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;}; |
| 1120 |
__pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; |
| 1121 |
return 0; |
| 1122 |
__pyx_L1_error:;
|
| 1123 |
return -1; |
| 1124 |
} |
| 1125 |
|
| 1126 |
#if PY_MAJOR_VERSION < 3 |
| 1127 |
PyMODINIT_FUNC initMetropolis(void); /*proto*/ |
| 1128 |
PyMODINIT_FUNC initMetropolis(void)
|
| 1129 |
#else
|
| 1130 |
PyMODINIT_FUNC PyInit_Metropolis(void); /*proto*/ |
| 1131 |
PyMODINIT_FUNC PyInit_Metropolis(void)
|
| 1132 |
#endif
|
| 1133 |
{
|
| 1134 |
PyObject *__pyx_t_1 = NULL;
|
| 1135 |
PyObject *__pyx_t_2 = NULL;
|
| 1136 |
__Pyx_RefNannyDeclarations |
| 1137 |
#if CYTHON_REFNANNY
|
| 1138 |
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
|
| 1139 |
if (!__Pyx_RefNanny) {
|
| 1140 |
PyErr_Clear(); |
| 1141 |
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
|
| 1142 |
if (!__Pyx_RefNanny)
|
| 1143 |
Py_FatalError("failed to import 'refnanny' module");
|
| 1144 |
} |
| 1145 |
#endif
|
| 1146 |
__Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_Metropolis(void)");
|
| 1147 |
if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1148 |
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1149 |
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1150 |
#ifdef __pyx_binding_PyCFunctionType_USED
|
| 1151 |
if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1152 |
#endif
|
| 1153 |
/*--- Library function declarations ---*/
|
| 1154 |
/*--- Threads initialization code ---*/
|
| 1155 |
#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
|
| 1156 |
#ifdef WITH_THREAD /* Python build with threading support? */ |
| 1157 |
PyEval_InitThreads(); |
| 1158 |
#endif
|
| 1159 |
#endif
|
| 1160 |
/*--- Module creation code ---*/
|
| 1161 |
#if PY_MAJOR_VERSION < 3 |
| 1162 |
__pyx_m = Py_InitModule4(__Pyx_NAMESTR("Metropolis"), __pyx_methods, 0, 0, PYTHON_API_VERSION); |
| 1163 |
#else
|
| 1164 |
__pyx_m = PyModule_Create(&__pyx_moduledef); |
| 1165 |
#endif
|
| 1166 |
if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; |
| 1167 |
#if PY_MAJOR_VERSION < 3 |
| 1168 |
Py_INCREF(__pyx_m); |
| 1169 |
#endif
|
| 1170 |
__pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); |
| 1171 |
if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; |
| 1172 |
if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; |
| 1173 |
/*--- Initialize various global constants etc. ---*/
|
| 1174 |
if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1175 |
if (__pyx_module_is_main_Metropolis) {
|
| 1176 |
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;}; |
| 1177 |
} |
| 1178 |
/*--- Builtin init code ---*/
|
| 1179 |
if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1180 |
/*--- Constants init code ---*/
|
| 1181 |
if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1182 |
/*--- Global init code ---*/
|
| 1183 |
/*--- Variable export code ---*/
|
| 1184 |
/*--- Function export code ---*/
|
| 1185 |
/*--- Type init code ---*/
|
| 1186 |
/*--- Type import code ---*/
|
| 1187 |
/*--- Variable import code ---*/
|
| 1188 |
/*--- Function import code ---*/
|
| 1189 |
/*--- Execution code ---*/
|
| 1190 |
|
| 1191 |
/* "Metropolis.pyx":7
|
| 1192 |
* # CC BY-NC-SA 2011 : <emmanuel.quemener@ens-lyon.fr>
|
| 1193 |
*
|
| 1194 |
* import sys # <<<<<<<<<<<<<<
|
| 1195 |
* import numpy
|
| 1196 |
* from PIL import Image
|
| 1197 |
*/
|
| 1198 |
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1199 |
__Pyx_GOTREF(__pyx_t_1); |
| 1200 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1201 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1202 |
|
| 1203 |
/* "Metropolis.pyx":8
|
| 1204 |
*
|
| 1205 |
* import sys
|
| 1206 |
* import numpy # <<<<<<<<<<<<<<
|
| 1207 |
* from PIL import Image
|
| 1208 |
* from math import exp
|
| 1209 |
*/
|
| 1210 |
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1211 |
__Pyx_GOTREF(__pyx_t_1); |
| 1212 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__numpy, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1213 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1214 |
|
| 1215 |
/* "Metropolis.pyx":9
|
| 1216 |
* import sys
|
| 1217 |
* import numpy
|
| 1218 |
* from PIL import Image # <<<<<<<<<<<<<<
|
| 1219 |
* from math import exp
|
| 1220 |
* from random import random
|
| 1221 |
*/
|
| 1222 |
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1223 |
__Pyx_GOTREF(((PyObject *)__pyx_t_1)); |
| 1224 |
__Pyx_INCREF(((PyObject *)__pyx_n_s__Image)); |
| 1225 |
PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__Image));
|
| 1226 |
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__Image)); |
| 1227 |
__pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__PIL), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1228 |
__Pyx_GOTREF(__pyx_t_2); |
| 1229 |
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
|
| 1230 |
__pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__Image); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1231 |
__Pyx_GOTREF(__pyx_t_1); |
| 1232 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Image, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1233 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1234 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 1235 |
|
| 1236 |
/* "Metropolis.pyx":10
|
| 1237 |
* import numpy
|
| 1238 |
* from PIL import Image
|
| 1239 |
* from math import exp # <<<<<<<<<<<<<<
|
| 1240 |
* from random import random
|
| 1241 |
* import time
|
| 1242 |
*/
|
| 1243 |
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1244 |
__Pyx_GOTREF(((PyObject *)__pyx_t_2)); |
| 1245 |
__Pyx_INCREF(((PyObject *)__pyx_n_s__exp)); |
| 1246 |
PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__exp));
|
| 1247 |
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__exp)); |
| 1248 |
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__math), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1249 |
__Pyx_GOTREF(__pyx_t_1); |
| 1250 |
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
|
| 1251 |
__pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__exp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1252 |
__Pyx_GOTREF(__pyx_t_2); |
| 1253 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__exp, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1254 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 1255 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1256 |
|
| 1257 |
/* "Metropolis.pyx":11
|
| 1258 |
* from PIL import Image
|
| 1259 |
* from math import exp
|
| 1260 |
* from random import random # <<<<<<<<<<<<<<
|
| 1261 |
* import time
|
| 1262 |
* import getopt
|
| 1263 |
*/
|
| 1264 |
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1265 |
__Pyx_GOTREF(((PyObject *)__pyx_t_1)); |
| 1266 |
__Pyx_INCREF(((PyObject *)__pyx_n_s__random)); |
| 1267 |
PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__random));
|
| 1268 |
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__random)); |
| 1269 |
__pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__random), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1270 |
__Pyx_GOTREF(__pyx_t_2); |
| 1271 |
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
|
| 1272 |
__pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__random); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1273 |
__Pyx_GOTREF(__pyx_t_1); |
| 1274 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1275 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1276 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 1277 |
|
| 1278 |
/* "Metropolis.pyx":12
|
| 1279 |
* from math import exp
|
| 1280 |
* from random import random
|
| 1281 |
* import time # <<<<<<<<<<<<<<
|
| 1282 |
* import getopt
|
| 1283 |
* import matplotlib.pyplot as plt
|
| 1284 |
*/
|
| 1285 |
__pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__time), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1286 |
__Pyx_GOTREF(__pyx_t_2); |
| 1287 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__time, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1288 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 1289 |
|
| 1290 |
/* "Metropolis.pyx":13
|
| 1291 |
* from random import random
|
| 1292 |
* import time
|
| 1293 |
* import getopt # <<<<<<<<<<<<<<
|
| 1294 |
* import matplotlib.pyplot as plt
|
| 1295 |
* import Metropolis
|
| 1296 |
*/
|
| 1297 |
__pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__getopt), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1298 |
__Pyx_GOTREF(__pyx_t_2); |
| 1299 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__getopt, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1300 |
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
|
| 1301 |
|
| 1302 |
/* "Metropolis.pyx":14
|
| 1303 |
* import time
|
| 1304 |
* import getopt
|
| 1305 |
* import matplotlib.pyplot as plt # <<<<<<<<<<<<<<
|
| 1306 |
* import Metropolis
|
| 1307 |
*
|
| 1308 |
*/
|
| 1309 |
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1310 |
__Pyx_GOTREF(((PyObject *)__pyx_t_2)); |
| 1311 |
__Pyx_INCREF(((PyObject *)__pyx_n_s_2)); |
| 1312 |
PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s_2));
|
| 1313 |
__Pyx_GIVEREF(((PyObject *)__pyx_n_s_2)); |
| 1314 |
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s_1), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1315 |
__Pyx_GOTREF(__pyx_t_1); |
| 1316 |
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
|
| 1317 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__plt, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1318 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1319 |
|
| 1320 |
/* "Metropolis.pyx":15
|
| 1321 |
* import getopt
|
| 1322 |
* import matplotlib.pyplot as plt
|
| 1323 |
* import Metropolis # <<<<<<<<<<<<<<
|
| 1324 |
*
|
| 1325 |
* def Metropolis(sigma,J,B,T,iterations):
|
| 1326 |
*/
|
| 1327 |
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__Metropolis), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1328 |
__Pyx_GOTREF(__pyx_t_1); |
| 1329 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Metropolis, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1330 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1331 |
|
| 1332 |
/* "Metropolis.pyx":17
|
| 1333 |
* import Metropolis
|
| 1334 |
*
|
| 1335 |
* def Metropolis(sigma,J,B,T,iterations): # <<<<<<<<<<<<<<
|
| 1336 |
* start=time.time()
|
| 1337 |
*
|
| 1338 |
*/
|
| 1339 |
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10Metropolis_Metropolis, NULL, __pyx_n_s__Metropolis); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1340 |
__Pyx_GOTREF(__pyx_t_1); |
| 1341 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Metropolis, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1342 |
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
| 1343 |
|
| 1344 |
/* "Metropolis.pyx":1
|
| 1345 |
* #!/usr/bin/env python # <<<<<<<<<<<<<<
|
| 1346 |
* #
|
| 1347 |
* # Ising2D model in serial mode
|
| 1348 |
*/
|
| 1349 |
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1350 |
__Pyx_GOTREF(((PyObject *)__pyx_t_1)); |
| 1351 |
if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} |
| 1352 |
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
|
| 1353 |
goto __pyx_L0;
|
| 1354 |
__pyx_L1_error:;
|
| 1355 |
__Pyx_XDECREF(__pyx_t_1); |
| 1356 |
__Pyx_XDECREF(__pyx_t_2); |
| 1357 |
if (__pyx_m) {
|
| 1358 |
__Pyx_AddTraceback("init Metropolis", __pyx_clineno, __pyx_lineno, __pyx_filename);
|
| 1359 |
Py_DECREF(__pyx_m); __pyx_m = 0;
|
| 1360 |
} else if (!PyErr_Occurred()) { |
| 1361 |
PyErr_SetString(PyExc_ImportError, "init Metropolis");
|
| 1362 |
} |
| 1363 |
__pyx_L0:;
|
| 1364 |
__Pyx_RefNannyFinishContext(); |
| 1365 |
#if PY_MAJOR_VERSION < 3 |
| 1366 |
return;
|
| 1367 |
#else
|
| 1368 |
return __pyx_m;
|
| 1369 |
#endif
|
| 1370 |
} |
| 1371 |
|
| 1372 |
/* Runtime support code */
|
| 1373 |
|
| 1374 |
#if CYTHON_REFNANNY
|
| 1375 |
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { |
| 1376 |
PyObject *m = NULL, *p = NULL; |
| 1377 |
void *r = NULL; |
| 1378 |
m = PyImport_ImportModule((char *)modname);
|
| 1379 |
if (!m) goto end; |
| 1380 |
p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); |
| 1381 |
if (!p) goto end; |
| 1382 |
r = PyLong_AsVoidPtr(p); |
| 1383 |
end:
|
| 1384 |
Py_XDECREF(p); |
| 1385 |
Py_XDECREF(m); |
| 1386 |
return (__Pyx_RefNannyAPIStruct *)r;
|
| 1387 |
} |
| 1388 |
#endif /* CYTHON_REFNANNY */ |
| 1389 |
|
| 1390 |
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
|
| 1391 |
PyObject *result; |
| 1392 |
result = PyObject_GetAttr(dict, name); |
| 1393 |
if (!result) {
|
| 1394 |
if (dict != __pyx_b) {
|
| 1395 |
PyErr_Clear(); |
| 1396 |
result = PyObject_GetAttr(__pyx_b, name); |
| 1397 |
} |
| 1398 |
if (!result) {
|
| 1399 |
PyErr_SetObject(PyExc_NameError, name); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
return result;
|
| 1403 |
} |
| 1404 |
|
| 1405 |
static void __Pyx_RaiseArgtupleInvalid( |
| 1406 |
const char* func_name, |
| 1407 |
int exact,
|
| 1408 |
Py_ssize_t num_min, |
| 1409 |
Py_ssize_t num_max, |
| 1410 |
Py_ssize_t num_found) |
| 1411 |
{
|
| 1412 |
Py_ssize_t num_expected; |
| 1413 |
const char *more_or_less; |
| 1414 |
|
| 1415 |
if (num_found < num_min) {
|
| 1416 |
num_expected = num_min; |
| 1417 |
more_or_less = "at least";
|
| 1418 |
} else {
|
| 1419 |
num_expected = num_max; |
| 1420 |
more_or_less = "at most";
|
| 1421 |
} |
| 1422 |
if (exact) {
|
| 1423 |
more_or_less = "exactly";
|
| 1424 |
} |
| 1425 |
PyErr_Format(PyExc_TypeError, |
| 1426 |
"%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", |
| 1427 |
func_name, more_or_less, num_expected, |
| 1428 |
(num_expected == 1) ? "" : "s", num_found); |
| 1429 |
} |
| 1430 |
|
| 1431 |
static void __Pyx_RaiseDoubleKeywordsError( |
| 1432 |
const char* func_name, |
| 1433 |
PyObject* kw_name) |
| 1434 |
{
|
| 1435 |
PyErr_Format(PyExc_TypeError, |
| 1436 |
#if PY_MAJOR_VERSION >= 3 |
| 1437 |
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
|
| 1438 |
#else
|
| 1439 |
"%s() got multiple values for keyword argument '%s'", func_name,
|
| 1440 |
PyString_AS_STRING(kw_name)); |
| 1441 |
#endif
|
| 1442 |
} |
| 1443 |
|
| 1444 |
static int __Pyx_ParseOptionalKeywords( |
| 1445 |
PyObject *kwds, |
| 1446 |
PyObject **argnames[], |
| 1447 |
PyObject *kwds2, |
| 1448 |
PyObject *values[], |
| 1449 |
Py_ssize_t num_pos_args, |
| 1450 |
const char* function_name) |
| 1451 |
{
|
| 1452 |
PyObject *key = 0, *value = 0; |
| 1453 |
Py_ssize_t pos = 0;
|
| 1454 |
PyObject*** name; |
| 1455 |
PyObject*** first_kw_arg = argnames + num_pos_args; |
| 1456 |
|
| 1457 |
while (PyDict_Next(kwds, &pos, &key, &value)) {
|
| 1458 |
name = first_kw_arg; |
| 1459 |
while (*name && (**name != key)) name++;
|
| 1460 |
if (*name) {
|
| 1461 |
values[name-argnames] = value; |
| 1462 |
} else {
|
| 1463 |
#if PY_MAJOR_VERSION < 3 |
| 1464 |
if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
|
| 1465 |
#else
|
| 1466 |
if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
|
| 1467 |
#endif
|
| 1468 |
goto invalid_keyword_type;
|
| 1469 |
} else {
|
| 1470 |
for (name = first_kw_arg; *name; name++) {
|
| 1471 |
#if PY_MAJOR_VERSION >= 3 |
| 1472 |
if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
|
| 1473 |
PyUnicode_Compare(**name, key) == 0) break; |
| 1474 |
#else
|
| 1475 |
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
|
| 1476 |
_PyString_Eq(**name, key)) break;
|
| 1477 |
#endif
|
| 1478 |
} |
| 1479 |
if (*name) {
|
| 1480 |
values[name-argnames] = value; |
| 1481 |
} else {
|
| 1482 |
/* unexpected keyword found */
|
| 1483 |
for (name=argnames; name != first_kw_arg; name++) {
|
| 1484 |
if (**name == key) goto arg_passed_twice; |
| 1485 |
#if PY_MAJOR_VERSION >= 3 |
| 1486 |
if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
|
| 1487 |
PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; |
| 1488 |
#else
|
| 1489 |
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
|
| 1490 |
_PyString_Eq(**name, key)) goto arg_passed_twice;
|
| 1491 |
#endif
|
| 1492 |
} |
| 1493 |
if (kwds2) {
|
| 1494 |
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; |
| 1495 |
} else {
|
| 1496 |
goto invalid_keyword;
|
| 1497 |
} |
| 1498 |
} |
| 1499 |
} |
| 1500 |
} |
| 1501 |
} |
| 1502 |
return 0; |
| 1503 |
arg_passed_twice:
|
| 1504 |
__Pyx_RaiseDoubleKeywordsError(function_name, **name); |
| 1505 |
goto bad;
|
| 1506 |
invalid_keyword_type:
|
| 1507 |
PyErr_Format(PyExc_TypeError, |
| 1508 |
"%s() keywords must be strings", function_name);
|
| 1509 |
goto bad;
|
| 1510 |
invalid_keyword:
|
| 1511 |
PyErr_Format(PyExc_TypeError, |
| 1512 |
#if PY_MAJOR_VERSION < 3 |
| 1513 |
"%s() got an unexpected keyword argument '%s'",
|
| 1514 |
function_name, PyString_AsString(key)); |
| 1515 |
#else
|
| 1516 |
"%s() got an unexpected keyword argument '%U'",
|
| 1517 |
function_name, key); |
| 1518 |
#endif
|
| 1519 |
bad:
|
| 1520 |
return -1; |
| 1521 |
} |
| 1522 |
|
| 1523 |
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { |
| 1524 |
PyErr_Format(PyExc_ValueError, |
| 1525 |
"need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", |
| 1526 |
index, (index == 1) ? "" : "s"); |
| 1527 |
} |
| 1528 |
|
| 1529 |
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { |
| 1530 |
PyErr_Format(PyExc_ValueError, |
| 1531 |
"too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); |
| 1532 |
} |
| 1533 |
|
| 1534 |
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { |
| 1535 |
if (unlikely(retval)) {
|
| 1536 |
Py_DECREF(retval); |
| 1537 |
__Pyx_RaiseTooManyValuesError(expected); |
| 1538 |
return -1; |
| 1539 |
} else if (PyErr_Occurred()) { |
| 1540 |
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
|
| 1541 |
PyErr_Clear(); |
| 1542 |
return 0; |
| 1543 |
} else {
|
| 1544 |
return -1; |
| 1545 |
} |
| 1546 |
} |
| 1547 |
return 0; |
| 1548 |
} |
| 1549 |
|
| 1550 |
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { |
| 1551 |
PyObject *py_import = 0;
|
| 1552 |
PyObject *empty_list = 0;
|
| 1553 |
PyObject *module = 0;
|
| 1554 |
PyObject *global_dict = 0;
|
| 1555 |
PyObject *empty_dict = 0;
|
| 1556 |
PyObject *list; |
| 1557 |
py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
|
| 1558 |
if (!py_import)
|
| 1559 |
goto bad;
|
| 1560 |
if (from_list)
|
| 1561 |
list = from_list; |
| 1562 |
else {
|
| 1563 |
empty_list = PyList_New(0);
|
| 1564 |
if (!empty_list)
|
| 1565 |
goto bad;
|
| 1566 |
list = empty_list; |
| 1567 |
} |
| 1568 |
global_dict = PyModule_GetDict(__pyx_m); |
| 1569 |
if (!global_dict)
|
| 1570 |
goto bad;
|
| 1571 |
empty_dict = PyDict_New(); |
| 1572 |
if (!empty_dict)
|
| 1573 |
goto bad;
|
| 1574 |
#if PY_VERSION_HEX >= 0x02050000 |
| 1575 |
{
|
| 1576 |
PyObject *py_level = PyInt_FromLong(level); |
| 1577 |
if (!py_level)
|
| 1578 |
goto bad;
|
| 1579 |
module = PyObject_CallFunctionObjArgs(py_import, |
| 1580 |
name, global_dict, empty_dict, list, py_level, NULL);
|
| 1581 |
Py_DECREF(py_level); |
| 1582 |
} |
| 1583 |
#else
|
| 1584 |
if (level>0) { |
| 1585 |
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
|
| 1586 |
goto bad;
|
| 1587 |
} |
| 1588 |
module = PyObject_CallFunctionObjArgs(py_import, |
| 1589 |
name, global_dict, empty_dict, list, NULL);
|
| 1590 |
#endif
|
| 1591 |
bad:
|
| 1592 |
Py_XDECREF(empty_list); |
| 1593 |
Py_XDECREF(py_import); |
| 1594 |
Py_XDECREF(empty_dict); |
| 1595 |
return module;
|
| 1596 |
} |
| 1597 |
|
| 1598 |
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { |
| 1599 |
const unsigned char neg_one = (unsigned char)-1, const_zero = 0; |
| 1600 |
const int is_unsigned = neg_one > const_zero; |
| 1601 |
if (sizeof(unsigned char) < sizeof(long)) { |
| 1602 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1603 |
if (unlikely(val != (long)(unsigned char)val)) { |
| 1604 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1605 |
PyErr_SetString(PyExc_OverflowError, |
| 1606 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1607 |
"can't convert negative value to unsigned char" :
|
| 1608 |
"value too large to convert to unsigned char");
|
| 1609 |
} |
| 1610 |
return (unsigned char)-1; |
| 1611 |
} |
| 1612 |
return (unsigned char)val; |
| 1613 |
} |
| 1614 |
return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); |
| 1615 |
} |
| 1616 |
|
| 1617 |
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { |
| 1618 |
const unsigned short neg_one = (unsigned short)-1, const_zero = 0; |
| 1619 |
const int is_unsigned = neg_one > const_zero; |
| 1620 |
if (sizeof(unsigned short) < sizeof(long)) { |
| 1621 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1622 |
if (unlikely(val != (long)(unsigned short)val)) { |
| 1623 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1624 |
PyErr_SetString(PyExc_OverflowError, |
| 1625 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1626 |
"can't convert negative value to unsigned short" :
|
| 1627 |
"value too large to convert to unsigned short");
|
| 1628 |
} |
| 1629 |
return (unsigned short)-1; |
| 1630 |
} |
| 1631 |
return (unsigned short)val; |
| 1632 |
} |
| 1633 |
return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); |
| 1634 |
} |
| 1635 |
|
| 1636 |
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { |
| 1637 |
const unsigned int neg_one = (unsigned int)-1, const_zero = 0; |
| 1638 |
const int is_unsigned = neg_one > const_zero; |
| 1639 |
if (sizeof(unsigned int) < sizeof(long)) { |
| 1640 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1641 |
if (unlikely(val != (long)(unsigned int)val)) { |
| 1642 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1643 |
PyErr_SetString(PyExc_OverflowError, |
| 1644 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1645 |
"can't convert negative value to unsigned int" :
|
| 1646 |
"value too large to convert to unsigned int");
|
| 1647 |
} |
| 1648 |
return (unsigned int)-1; |
| 1649 |
} |
| 1650 |
return (unsigned int)val; |
| 1651 |
} |
| 1652 |
return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); |
| 1653 |
} |
| 1654 |
|
| 1655 |
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { |
| 1656 |
const char neg_one = (char)-1, const_zero = 0; |
| 1657 |
const int is_unsigned = neg_one > const_zero; |
| 1658 |
if (sizeof(char) < sizeof(long)) { |
| 1659 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1660 |
if (unlikely(val != (long)(char)val)) { |
| 1661 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1662 |
PyErr_SetString(PyExc_OverflowError, |
| 1663 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1664 |
"can't convert negative value to char" :
|
| 1665 |
"value too large to convert to char");
|
| 1666 |
} |
| 1667 |
return (char)-1; |
| 1668 |
} |
| 1669 |
return (char)val; |
| 1670 |
} |
| 1671 |
return (char)__Pyx_PyInt_AsLong(x); |
| 1672 |
} |
| 1673 |
|
| 1674 |
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { |
| 1675 |
const short neg_one = (short)-1, const_zero = 0; |
| 1676 |
const int is_unsigned = neg_one > const_zero; |
| 1677 |
if (sizeof(short) < sizeof(long)) { |
| 1678 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1679 |
if (unlikely(val != (long)(short)val)) { |
| 1680 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1681 |
PyErr_SetString(PyExc_OverflowError, |
| 1682 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1683 |
"can't convert negative value to short" :
|
| 1684 |
"value too large to convert to short");
|
| 1685 |
} |
| 1686 |
return (short)-1; |
| 1687 |
} |
| 1688 |
return (short)val; |
| 1689 |
} |
| 1690 |
return (short)__Pyx_PyInt_AsLong(x); |
| 1691 |
} |
| 1692 |
|
| 1693 |
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { |
| 1694 |
const int neg_one = (int)-1, const_zero = 0; |
| 1695 |
const int is_unsigned = neg_one > const_zero; |
| 1696 |
if (sizeof(int) < sizeof(long)) { |
| 1697 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1698 |
if (unlikely(val != (long)(int)val)) { |
| 1699 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1700 |
PyErr_SetString(PyExc_OverflowError, |
| 1701 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1702 |
"can't convert negative value to int" :
|
| 1703 |
"value too large to convert to int");
|
| 1704 |
} |
| 1705 |
return (int)-1; |
| 1706 |
} |
| 1707 |
return (int)val; |
| 1708 |
} |
| 1709 |
return (int)__Pyx_PyInt_AsLong(x); |
| 1710 |
} |
| 1711 |
|
| 1712 |
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { |
| 1713 |
const signed char neg_one = (signed char)-1, const_zero = 0; |
| 1714 |
const int is_unsigned = neg_one > const_zero; |
| 1715 |
if (sizeof(signed char) < sizeof(long)) { |
| 1716 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1717 |
if (unlikely(val != (long)(signed char)val)) { |
| 1718 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1719 |
PyErr_SetString(PyExc_OverflowError, |
| 1720 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1721 |
"can't convert negative value to signed char" :
|
| 1722 |
"value too large to convert to signed char");
|
| 1723 |
} |
| 1724 |
return (signed char)-1; |
| 1725 |
} |
| 1726 |
return (signed char)val; |
| 1727 |
} |
| 1728 |
return (signed char)__Pyx_PyInt_AsSignedLong(x); |
| 1729 |
} |
| 1730 |
|
| 1731 |
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { |
| 1732 |
const signed short neg_one = (signed short)-1, const_zero = 0; |
| 1733 |
const int is_unsigned = neg_one > const_zero; |
| 1734 |
if (sizeof(signed short) < sizeof(long)) { |
| 1735 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1736 |
if (unlikely(val != (long)(signed short)val)) { |
| 1737 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1738 |
PyErr_SetString(PyExc_OverflowError, |
| 1739 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1740 |
"can't convert negative value to signed short" :
|
| 1741 |
"value too large to convert to signed short");
|
| 1742 |
} |
| 1743 |
return (signed short)-1; |
| 1744 |
} |
| 1745 |
return (signed short)val; |
| 1746 |
} |
| 1747 |
return (signed short)__Pyx_PyInt_AsSignedLong(x); |
| 1748 |
} |
| 1749 |
|
| 1750 |
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { |
| 1751 |
const signed int neg_one = (signed int)-1, const_zero = 0; |
| 1752 |
const int is_unsigned = neg_one > const_zero; |
| 1753 |
if (sizeof(signed int) < sizeof(long)) { |
| 1754 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1755 |
if (unlikely(val != (long)(signed int)val)) { |
| 1756 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1757 |
PyErr_SetString(PyExc_OverflowError, |
| 1758 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1759 |
"can't convert negative value to signed int" :
|
| 1760 |
"value too large to convert to signed int");
|
| 1761 |
} |
| 1762 |
return (signed int)-1; |
| 1763 |
} |
| 1764 |
return (signed int)val; |
| 1765 |
} |
| 1766 |
return (signed int)__Pyx_PyInt_AsSignedLong(x); |
| 1767 |
} |
| 1768 |
|
| 1769 |
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { |
| 1770 |
const int neg_one = (int)-1, const_zero = 0; |
| 1771 |
const int is_unsigned = neg_one > const_zero; |
| 1772 |
if (sizeof(int) < sizeof(long)) { |
| 1773 |
long val = __Pyx_PyInt_AsLong(x);
|
| 1774 |
if (unlikely(val != (long)(int)val)) { |
| 1775 |
if (!unlikely(val == -1 && PyErr_Occurred())) { |
| 1776 |
PyErr_SetString(PyExc_OverflowError, |
| 1777 |
(is_unsigned && unlikely(val < 0)) ?
|
| 1778 |
"can't convert negative value to int" :
|
| 1779 |
"value too large to convert to int");
|
| 1780 |
} |
| 1781 |
return (int)-1; |
| 1782 |
} |
| 1783 |
return (int)val; |
| 1784 |
} |
| 1785 |
return (int)__Pyx_PyInt_AsLong(x); |
| 1786 |
} |
| 1787 |
|
| 1788 |
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { |
| 1789 |
const unsigned long neg_one = (unsigned long)-1, const_zero = 0; |
| 1790 |
const int is_unsigned = neg_one > const_zero; |
| 1791 |
#if PY_VERSION_HEX < 0x03000000 |
| 1792 |
if (likely(PyInt_Check(x))) {
|
| 1793 |
long val = PyInt_AS_LONG(x);
|
| 1794 |
if (is_unsigned && unlikely(val < 0)) { |
| 1795 |
PyErr_SetString(PyExc_OverflowError, |
| 1796 |
"can't convert negative value to unsigned long");
|
| 1797 |
return (unsigned long)-1; |
| 1798 |
} |
| 1799 |
return (unsigned long)val; |
| 1800 |
} else
|
| 1801 |
#endif
|
| 1802 |
if (likely(PyLong_Check(x))) {
|
| 1803 |
if (is_unsigned) {
|
| 1804 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1805 |
PyErr_SetString(PyExc_OverflowError, |
| 1806 |
"can't convert negative value to unsigned long");
|
| 1807 |
return (unsigned long)-1; |
| 1808 |
} |
| 1809 |
return (unsigned long)PyLong_AsUnsignedLong(x); |
| 1810 |
} else {
|
| 1811 |
return (unsigned long)PyLong_AsLong(x); |
| 1812 |
} |
| 1813 |
} else {
|
| 1814 |
unsigned long val; |
| 1815 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1816 |
if (!tmp) return (unsigned long)-1; |
| 1817 |
val = __Pyx_PyInt_AsUnsignedLong(tmp); |
| 1818 |
Py_DECREF(tmp); |
| 1819 |
return val;
|
| 1820 |
} |
| 1821 |
} |
| 1822 |
|
| 1823 |
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { |
| 1824 |
const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; |
| 1825 |
const int is_unsigned = neg_one > const_zero; |
| 1826 |
#if PY_VERSION_HEX < 0x03000000 |
| 1827 |
if (likely(PyInt_Check(x))) {
|
| 1828 |
long val = PyInt_AS_LONG(x);
|
| 1829 |
if (is_unsigned && unlikely(val < 0)) { |
| 1830 |
PyErr_SetString(PyExc_OverflowError, |
| 1831 |
"can't convert negative value to unsigned PY_LONG_LONG");
|
| 1832 |
return (unsigned PY_LONG_LONG)-1; |
| 1833 |
} |
| 1834 |
return (unsigned PY_LONG_LONG)val; |
| 1835 |
} else
|
| 1836 |
#endif
|
| 1837 |
if (likely(PyLong_Check(x))) {
|
| 1838 |
if (is_unsigned) {
|
| 1839 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1840 |
PyErr_SetString(PyExc_OverflowError, |
| 1841 |
"can't convert negative value to unsigned PY_LONG_LONG");
|
| 1842 |
return (unsigned PY_LONG_LONG)-1; |
| 1843 |
} |
| 1844 |
return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); |
| 1845 |
} else {
|
| 1846 |
return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); |
| 1847 |
} |
| 1848 |
} else {
|
| 1849 |
unsigned PY_LONG_LONG val;
|
| 1850 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1851 |
if (!tmp) return (unsigned PY_LONG_LONG)-1; |
| 1852 |
val = __Pyx_PyInt_AsUnsignedLongLong(tmp); |
| 1853 |
Py_DECREF(tmp); |
| 1854 |
return val;
|
| 1855 |
} |
| 1856 |
} |
| 1857 |
|
| 1858 |
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { |
| 1859 |
const long neg_one = (long)-1, const_zero = 0; |
| 1860 |
const int is_unsigned = neg_one > const_zero; |
| 1861 |
#if PY_VERSION_HEX < 0x03000000 |
| 1862 |
if (likely(PyInt_Check(x))) {
|
| 1863 |
long val = PyInt_AS_LONG(x);
|
| 1864 |
if (is_unsigned && unlikely(val < 0)) { |
| 1865 |
PyErr_SetString(PyExc_OverflowError, |
| 1866 |
"can't convert negative value to long");
|
| 1867 |
return (long)-1; |
| 1868 |
} |
| 1869 |
return (long)val; |
| 1870 |
} else
|
| 1871 |
#endif
|
| 1872 |
if (likely(PyLong_Check(x))) {
|
| 1873 |
if (is_unsigned) {
|
| 1874 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1875 |
PyErr_SetString(PyExc_OverflowError, |
| 1876 |
"can't convert negative value to long");
|
| 1877 |
return (long)-1; |
| 1878 |
} |
| 1879 |
return (long)PyLong_AsUnsignedLong(x); |
| 1880 |
} else {
|
| 1881 |
return (long)PyLong_AsLong(x); |
| 1882 |
} |
| 1883 |
} else {
|
| 1884 |
long val;
|
| 1885 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1886 |
if (!tmp) return (long)-1; |
| 1887 |
val = __Pyx_PyInt_AsLong(tmp); |
| 1888 |
Py_DECREF(tmp); |
| 1889 |
return val;
|
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
|
| 1894 |
const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; |
| 1895 |
const int is_unsigned = neg_one > const_zero; |
| 1896 |
#if PY_VERSION_HEX < 0x03000000 |
| 1897 |
if (likely(PyInt_Check(x))) {
|
| 1898 |
long val = PyInt_AS_LONG(x);
|
| 1899 |
if (is_unsigned && unlikely(val < 0)) { |
| 1900 |
PyErr_SetString(PyExc_OverflowError, |
| 1901 |
"can't convert negative value to PY_LONG_LONG");
|
| 1902 |
return (PY_LONG_LONG)-1; |
| 1903 |
} |
| 1904 |
return (PY_LONG_LONG)val;
|
| 1905 |
} else
|
| 1906 |
#endif
|
| 1907 |
if (likely(PyLong_Check(x))) {
|
| 1908 |
if (is_unsigned) {
|
| 1909 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1910 |
PyErr_SetString(PyExc_OverflowError, |
| 1911 |
"can't convert negative value to PY_LONG_LONG");
|
| 1912 |
return (PY_LONG_LONG)-1; |
| 1913 |
} |
| 1914 |
return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
|
| 1915 |
} else {
|
| 1916 |
return (PY_LONG_LONG)PyLong_AsLongLong(x);
|
| 1917 |
} |
| 1918 |
} else {
|
| 1919 |
PY_LONG_LONG val; |
| 1920 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1921 |
if (!tmp) return (PY_LONG_LONG)-1; |
| 1922 |
val = __Pyx_PyInt_AsLongLong(tmp); |
| 1923 |
Py_DECREF(tmp); |
| 1924 |
return val;
|
| 1925 |
} |
| 1926 |
} |
| 1927 |
|
| 1928 |
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { |
| 1929 |
const signed long neg_one = (signed long)-1, const_zero = 0; |
| 1930 |
const int is_unsigned = neg_one > const_zero; |
| 1931 |
#if PY_VERSION_HEX < 0x03000000 |
| 1932 |
if (likely(PyInt_Check(x))) {
|
| 1933 |
long val = PyInt_AS_LONG(x);
|
| 1934 |
if (is_unsigned && unlikely(val < 0)) { |
| 1935 |
PyErr_SetString(PyExc_OverflowError, |
| 1936 |
"can't convert negative value to signed long");
|
| 1937 |
return (signed long)-1; |
| 1938 |
} |
| 1939 |
return (signed long)val; |
| 1940 |
} else
|
| 1941 |
#endif
|
| 1942 |
if (likely(PyLong_Check(x))) {
|
| 1943 |
if (is_unsigned) {
|
| 1944 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1945 |
PyErr_SetString(PyExc_OverflowError, |
| 1946 |
"can't convert negative value to signed long");
|
| 1947 |
return (signed long)-1; |
| 1948 |
} |
| 1949 |
return (signed long)PyLong_AsUnsignedLong(x); |
| 1950 |
} else {
|
| 1951 |
return (signed long)PyLong_AsLong(x); |
| 1952 |
} |
| 1953 |
} else {
|
| 1954 |
signed long val; |
| 1955 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1956 |
if (!tmp) return (signed long)-1; |
| 1957 |
val = __Pyx_PyInt_AsSignedLong(tmp); |
| 1958 |
Py_DECREF(tmp); |
| 1959 |
return val;
|
| 1960 |
} |
| 1961 |
} |
| 1962 |
|
| 1963 |
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { |
| 1964 |
const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; |
| 1965 |
const int is_unsigned = neg_one > const_zero; |
| 1966 |
#if PY_VERSION_HEX < 0x03000000 |
| 1967 |
if (likely(PyInt_Check(x))) {
|
| 1968 |
long val = PyInt_AS_LONG(x);
|
| 1969 |
if (is_unsigned && unlikely(val < 0)) { |
| 1970 |
PyErr_SetString(PyExc_OverflowError, |
| 1971 |
"can't convert negative value to signed PY_LONG_LONG");
|
| 1972 |
return (signed PY_LONG_LONG)-1; |
| 1973 |
} |
| 1974 |
return (signed PY_LONG_LONG)val; |
| 1975 |
} else
|
| 1976 |
#endif
|
| 1977 |
if (likely(PyLong_Check(x))) {
|
| 1978 |
if (is_unsigned) {
|
| 1979 |
if (unlikely(Py_SIZE(x) < 0)) { |
| 1980 |
PyErr_SetString(PyExc_OverflowError, |
| 1981 |
"can't convert negative value to signed PY_LONG_LONG");
|
| 1982 |
return (signed PY_LONG_LONG)-1; |
| 1983 |
} |
| 1984 |
return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); |
| 1985 |
} else {
|
| 1986 |
return (signed PY_LONG_LONG)PyLong_AsLongLong(x); |
| 1987 |
} |
| 1988 |
} else {
|
| 1989 |
signed PY_LONG_LONG val;
|
| 1990 |
PyObject *tmp = __Pyx_PyNumber_Int(x); |
| 1991 |
if (!tmp) return (signed PY_LONG_LONG)-1; |
| 1992 |
val = __Pyx_PyInt_AsSignedLongLong(tmp); |
| 1993 |
Py_DECREF(tmp); |
| 1994 |
return val;
|
| 1995 |
} |
| 1996 |
} |
| 1997 |
|
| 1998 |
static int __Pyx_check_binary_version(void) { |
| 1999 |
char ctversion[4], rtversion[4]; |
| 2000 |
PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); |
| 2001 |
PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); |
| 2002 |
if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { |
| 2003 |
char message[200]; |
| 2004 |
PyOS_snprintf(message, sizeof(message),
|
| 2005 |
"compiletime version %s of module '%.100s' "
|
| 2006 |
"does not match runtime version %s",
|
| 2007 |
ctversion, __Pyx_MODULE_NAME, rtversion); |
| 2008 |
#if PY_VERSION_HEX < 0x02050000 |
| 2009 |
return PyErr_Warn(NULL, message); |
| 2010 |
#else
|
| 2011 |
return PyErr_WarnEx(NULL, message, 1); |
| 2012 |
#endif
|
| 2013 |
} |
| 2014 |
return 0; |
| 2015 |
} |
| 2016 |
|
| 2017 |
#include "compile.h" |
| 2018 |
#include "frameobject.h" |
| 2019 |
#include "traceback.h" |
| 2020 |
|
| 2021 |
static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno, |
| 2022 |
int __pyx_lineno, const char *__pyx_filename) { |
| 2023 |
PyObject *py_srcfile = 0;
|
| 2024 |
PyObject *py_funcname = 0;
|
| 2025 |
PyObject *py_globals = 0;
|
| 2026 |
PyCodeObject *py_code = 0;
|
| 2027 |
PyFrameObject *py_frame = 0;
|
| 2028 |
|
| 2029 |
#if PY_MAJOR_VERSION < 3 |
| 2030 |
py_srcfile = PyString_FromString(__pyx_filename); |
| 2031 |
#else
|
| 2032 |
py_srcfile = PyUnicode_FromString(__pyx_filename); |
| 2033 |
#endif
|
| 2034 |
if (!py_srcfile) goto bad; |
| 2035 |
if (__pyx_clineno) {
|
| 2036 |
#if PY_MAJOR_VERSION < 3 |
| 2037 |
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
|
| 2038 |
#else
|
| 2039 |
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
|
| 2040 |
#endif
|
| 2041 |
} |
| 2042 |
else {
|
| 2043 |
#if PY_MAJOR_VERSION < 3 |
| 2044 |
py_funcname = PyString_FromString(funcname); |
| 2045 |
#else
|
| 2046 |
py_funcname = PyUnicode_FromString(funcname); |
| 2047 |
#endif
|
| 2048 |
} |
| 2049 |
if (!py_funcname) goto bad; |
| 2050 |
py_globals = PyModule_GetDict(__pyx_m); |
| 2051 |
if (!py_globals) goto bad; |
| 2052 |
py_code = PyCode_New( |
| 2053 |
0, /*int argcount,*/ |
| 2054 |
#if PY_MAJOR_VERSION >= 3 |
| 2055 |
0, /*int kwonlyargcount,*/ |
| 2056 |
#endif
|
| 2057 |
0, /*int nlocals,*/ |
| 2058 |
0, /*int stacksize,*/ |
| 2059 |
0, /*int flags,*/ |
| 2060 |
__pyx_empty_bytes, /*PyObject *code,*/
|
| 2061 |
__pyx_empty_tuple, /*PyObject *consts,*/
|
| 2062 |
__pyx_empty_tuple, /*PyObject *names,*/
|
| 2063 |
__pyx_empty_tuple, /*PyObject *varnames,*/
|
| 2064 |
__pyx_empty_tuple, /*PyObject *freevars,*/
|
| 2065 |
__pyx_empty_tuple, /*PyObject *cellvars,*/
|
| 2066 |
py_srcfile, /*PyObject *filename,*/
|
| 2067 |
py_funcname, /*PyObject *name,*/
|
| 2068 |
__pyx_lineno, /*int firstlineno,*/
|
| 2069 |
__pyx_empty_bytes /*PyObject *lnotab*/
|
| 2070 |
); |
| 2071 |
if (!py_code) goto bad; |
| 2072 |
py_frame = PyFrame_New( |
| 2073 |
PyThreadState_GET(), /*PyThreadState *tstate,*/
|
| 2074 |
py_code, /*PyCodeObject *code,*/
|
| 2075 |
py_globals, /*PyObject *globals,*/
|
| 2076 |
0 /*PyObject *locals*/ |
| 2077 |
); |
| 2078 |
if (!py_frame) goto bad; |
| 2079 |
py_frame->f_lineno = __pyx_lineno; |
| 2080 |
PyTraceBack_Here(py_frame); |
| 2081 |
bad:
|
| 2082 |
Py_XDECREF(py_srcfile); |
| 2083 |
Py_XDECREF(py_funcname); |
| 2084 |
Py_XDECREF(py_code); |
| 2085 |
Py_XDECREF(py_frame); |
| 2086 |
} |
| 2087 |
|
| 2088 |
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { |
| 2089 |
while (t->p) {
|
| 2090 |
#if PY_MAJOR_VERSION < 3 |
| 2091 |
if (t->is_unicode) {
|
| 2092 |
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); |
| 2093 |
} else if (t->intern) { |
| 2094 |
*t->p = PyString_InternFromString(t->s); |
| 2095 |
} else {
|
| 2096 |
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
|
| 2097 |
} |
| 2098 |
#else /* Python 3+ has unicode identifiers */ |
| 2099 |
if (t->is_unicode | t->is_str) {
|
| 2100 |
if (t->intern) {
|
| 2101 |
*t->p = PyUnicode_InternFromString(t->s); |
| 2102 |
} else if (t->encoding) { |
| 2103 |
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); |
| 2104 |
} else {
|
| 2105 |
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
|
| 2106 |
} |
| 2107 |
} else {
|
| 2108 |
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
|
| 2109 |
} |
| 2110 |
#endif
|
| 2111 |
if (!*t->p)
|
| 2112 |
return -1; |
| 2113 |
++t; |
| 2114 |
} |
| 2115 |
return 0; |
| 2116 |
} |
| 2117 |
|
| 2118 |
/* Type Conversion Functions */
|
| 2119 |
|
| 2120 |
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { |
| 2121 |
int is_true = x == Py_True;
|
| 2122 |
if (is_true | (x == Py_False) | (x == Py_None)) return is_true; |
| 2123 |
else return PyObject_IsTrue(x); |
| 2124 |
} |
| 2125 |
|
| 2126 |
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
|
| 2127 |
PyNumberMethods *m; |
| 2128 |
const char *name = NULL; |
| 2129 |
PyObject *res = NULL;
|
| 2130 |
#if PY_VERSION_HEX < 0x03000000 |
| 2131 |
if (PyInt_Check(x) || PyLong_Check(x))
|
| 2132 |
#else
|
| 2133 |
if (PyLong_Check(x))
|
| 2134 |
#endif
|
| 2135 |
return Py_INCREF(x), x;
|
| 2136 |
m = Py_TYPE(x)->tp_as_number; |
| 2137 |
#if PY_VERSION_HEX < 0x03000000 |
| 2138 |
if (m && m->nb_int) {
|
| 2139 |
name = "int";
|
| 2140 |
res = PyNumber_Int(x); |
| 2141 |
} |
| 2142 |
else if (m && m->nb_long) { |
| 2143 |
name = "long";
|
| 2144 |
res = PyNumber_Long(x); |
| 2145 |
} |
| 2146 |
#else
|
| 2147 |
if (m && m->nb_int) {
|
| 2148 |
name = "int";
|
| 2149 |
res = PyNumber_Long(x); |
| 2150 |
} |
| 2151 |
#endif
|
| 2152 |
if (res) {
|
| 2153 |
#if PY_VERSION_HEX < 0x03000000 |
| 2154 |
if (!PyInt_Check(res) && !PyLong_Check(res)) {
|
| 2155 |
#else
|
| 2156 |
if (!PyLong_Check(res)) {
|
| 2157 |
#endif
|
| 2158 |
PyErr_Format(PyExc_TypeError, |
| 2159 |
"__%s__ returned non-%s (type %.200s)",
|
| 2160 |
name, name, Py_TYPE(res)->tp_name); |
| 2161 |
Py_DECREF(res); |
| 2162 |
return NULL; |
| 2163 |
} |
| 2164 |
} |
| 2165 |
else if (!PyErr_Occurred()) { |
| 2166 |
PyErr_SetString(PyExc_TypeError, |
| 2167 |
"an integer is required");
|
| 2168 |
} |
| 2169 |
return res;
|
| 2170 |
} |
| 2171 |
|
| 2172 |
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
|
| 2173 |
Py_ssize_t ival; |
| 2174 |
PyObject* x = PyNumber_Index(b); |
| 2175 |
if (!x) return -1; |
| 2176 |
ival = PyInt_AsSsize_t(x); |
| 2177 |
Py_DECREF(x); |
| 2178 |
return ival;
|
| 2179 |
} |
| 2180 |
|
| 2181 |
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
|
| 2182 |
#if PY_VERSION_HEX < 0x02050000 |
| 2183 |
if (ival <= LONG_MAX)
|
| 2184 |
return PyInt_FromLong((long)ival); |
| 2185 |
else {
|
| 2186 |
unsigned char *bytes = (unsigned char *) &ival; |
| 2187 |
int one = 1; int little = (int)*(unsigned char*)&one; |
| 2188 |
return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); |
| 2189 |
} |
| 2190 |
#else
|
| 2191 |
return PyInt_FromSize_t(ival);
|
| 2192 |
#endif
|
| 2193 |
} |
| 2194 |
|
| 2195 |
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
|
| 2196 |
unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
|
| 2197 |
if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { |
| 2198 |
return (size_t)-1; |
| 2199 |
} else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { |
| 2200 |
PyErr_SetString(PyExc_OverflowError, |
| 2201 |
"value too large to convert to size_t");
|
| 2202 |
return (size_t)-1; |
| 2203 |
} |
| 2204 |
return (size_t)val;
|
| 2205 |
} |
| 2206 |
|
| 2207 |
|
| 2208 |
#endif /* Py_PYTHON_H */ |