Révision 18

Ising/Cython/Metropolis.pyx (revision 18)
1
#!/usr/bin/env python
2
#
3
# Ising2D model in serial mode
4
#
5
# CC BY-NC-SA 2011 : <emmanuel.quemener@ens-lyon.fr> 
6

  
7
import sys
8
import numpy
9
from PIL import Image
10
from math import exp
11
from random import random
12
import time
13
import getopt
14
import matplotlib.pyplot as plt
15
import Metropolis
16

  
17
def Metropolis(sigma,J,B,T,iterations): 
18
    start=time.time()
19

  
20
    SizeX,SizeY=sigma.shape
21
    
22
    for p in xrange(0,iterations):
23
        # Random access coordonate
24
        X,Y=numpy.random.randint(SizeX),numpy.random.randint(SizeY)
25
        
26
        DeltaE=J*sigma[X,Y]*(2*(sigma[X,(Y+1)%SizeY]+
27
                                sigma[X,(Y-1)%SizeY]+
28
                                sigma[(X-1)%SizeX,Y]+
29
                                sigma[(X+1)%SizeX,Y])+B)
30
        
31
        if DeltaE < 0. or random() < exp(-DeltaE/T):
32
            sigma[X,Y]=-sigma[X,Y]
33
    duration=time.time()-start
34
    return(duration)
0 35

  
Ising/Cython/Metropolis.c (revision 18)
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
{
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff