├── ClassCythonCPP ├── ExampleUsage.py ├── TestClass.pyx ├── TestClassC.cpp ├── makefile └── setup.py ├── ClassCythonCPPWithMemberFunctions ├── ExampleUsage.py ├── TestClass.pyx ├── TestClassC.cpp ├── makefile └── setup.py ├── HelloWorld ├── helloworld.pyx ├── helloworldC.cpp ├── makefile ├── minimalRunScript.py └── setup.py ├── HelloWorldOpenMP ├── helloworld.pyx ├── helloworldC.cpp ├── makefile ├── minimalRunScript.py └── setup.py ├── KalmanFilterC ├── CythonExample.cpp ├── CythonExample.pyx ├── KalmanFilter.cpp ├── KalmanFilter.pyx ├── KalmanFilterC.cpp ├── KalmanFilterPurePython.py ├── MatrixFunctions.h ├── UseKalmanFilterCython.py ├── makefile └── setup.py ├── README.md ├── SumNumpyArray ├── SumArray │ ├── SumArray.pyx │ ├── SumArrayC.cpp │ ├── __init__.py │ ├── makefile │ └── setup.py ├── SumArrayParallel │ ├── SumArrayCOpenMP.cpp │ ├── SumArrayParallel.pyx │ ├── __init__.py │ ├── makefile │ └── setupOpenMP.py ├── TimeComparison.py └── TimeComparison.py~ └── cythonSumPackage └── cythonSumPackage ├── MANIFEST.in ├── cythonSumPackage ├── SumArrayCython │ ├── SumArray.c │ ├── SumArray.pyx │ ├── __init__.py │ └── setup.py ├── UseSumArrayCython │ ├── UseSumArrayCython.py │ └── __init__.py ├── __init__.py └── core.py ├── install.sh └── setup.py /ClassCythonCPP/ExampleUsage.py: -------------------------------------------------------------------------------- 1 | import TestClass 2 | 3 | Tc = TestClass.CTestClass(5) 4 | 5 | del(Tc) 6 | 7 | -------------------------------------------------------------------------------- /ClassCythonCPP/TestClass.pyx: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | cdef extern from "TestClassC.cpp": # defines the source C++ file 4 | cdef cppclass TestClass: # says that there is a class defined in the above C++ file called TestClass 5 | TestClass(int Dimensionality) # the class has public member function TestClass which takes some arguments 6 | int Dimensionality # the class has a public variable that is an integer and is called Dimensionality 7 | 8 | cdef class CTestClass: # defines a python wrapper to the C++ class 9 | cdef TestClass* thisptr # thisptr is a pointer that will hold to the instance of the C++ class 10 | def __cinit__(self, int Dimensionality): # defines the python wrapper class' init function 11 | self.thisptr = new TestClass(Dimensionality) # creates an instance of the C++ class and puts allocates the pointer to this 12 | def __dealloc__(self): # defines the python wrapper class' deallocation function (python destructor) 13 | del self.thisptr # destroys the reference to the C++ instance (which calls the C++ class destructor 14 | 15 | -------------------------------------------------------------------------------- /ClassCythonCPP/TestClassC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class TestClass{ 4 | public: 5 | TestClass(int Dimensionality); // prototype of constructor 6 | ~TestClass(void); // prototype of destructor 7 | int Dimensionality; 8 | }; 9 | 10 | TestClass::TestClass(int DIM) 11 | { 12 | Dimensionality = DIM; 13 | std::cout << Dimensionality << "\n"; 14 | }; 15 | 16 | TestClass::~TestClass(void){ 17 | std::cout << "Being Destroyed" << "\n"; 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /ClassCythonCPP/makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python setup.py build_ext --inplace 3 | -------------------------------------------------------------------------------- /ClassCythonCPP/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | from Cython.Build import cythonize 4 | import numpy 5 | 6 | ext = Extension('TestClass', sources=["TestClass.pyx"], language="c++", include_dirs=[numpy.get_include()]) 7 | 8 | setup(name="TestClass", ext_modules = cythonize([ext])) 9 | -------------------------------------------------------------------------------- /ClassCythonCPPWithMemberFunctions/ExampleUsage.py: -------------------------------------------------------------------------------- 1 | import TestClass 2 | import numpy as np 3 | 4 | ListOfNums = np.array([0, 0.4, 0.7, 0.2, 8.0, 3.14159]) 5 | L = len(ListOfNums) 6 | 7 | Tc = TestClass.CTestClass(L, ListOfNums) 8 | 9 | SumTotal = Tc.CSumListOfNumbers() 10 | 11 | print(SumTotal) 12 | 13 | del(Tc) 14 | 15 | -------------------------------------------------------------------------------- /ClassCythonCPPWithMemberFunctions/TestClass.pyx: -------------------------------------------------------------------------------- 1 | import cython 2 | import numpy as np 3 | cimport numpy as np 4 | 5 | cdef extern from "TestClassC.cpp": # defines the source C++ file 6 | cdef cppclass TestClass: # says that there is a class defined in the above C++ file called TestClass 7 | TestClass(int Dimensionality, double* InputArray) # the class has public member function TestClass which takes some arguments 8 | double SumListOfNumbers() # the class has a public member function which returns a double and has no arguments 9 | int Dimensionality # the class has a public variable that is an integer and is called Dimensionality 10 | double* ListOfNumbers # the class has another public variable that is a pointer to a double 11 | 12 | cdef class CTestClass: # defines a python wrapper to the C++ class 13 | cdef TestClass* thisptr # thisptr is a pointer that will hold to the instance of the C++ class 14 | def __cinit__(self, int Dimensionality, np.ndarray[double, ndim=1, mode="c"] InputArray not None): # defines the python wrapper class' init function 15 | cdef double[::1] InputArrayC = InputArray # defines a memoryview containnig a 1D numpy array - this can be passed as a C-like array by providing a pointer to the 1st element and the length 16 | self.thisptr = new TestClass(Dimensionality, &InputArrayC[0]) # creates an instance of the C++ class and puts allocates the pointer to this 17 | def __dealloc__(self): # defines the python wrapper class' deallocation function (python destructor) 18 | del self.thisptr # destroys the reference to the C++ instance (which calls the C++ class destructor 19 | def CSumListOfNumbers(self): 20 | return self.thisptr.SumListOfNumbers() 21 | -------------------------------------------------------------------------------- /ClassCythonCPPWithMemberFunctions/TestClassC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class TestClass{ 4 | public: 5 | TestClass(int Dimensionality, double* InputArray); // prototype of constructor 6 | ~TestClass(void); // prototype of destructor 7 | double SumListOfNumbers(void); 8 | int Dimensionality; 9 | double* ListOfNumbers; 10 | }; 11 | 12 | TestClass::TestClass(int DIM, double* InputArray) 13 | { 14 | Dimensionality = DIM; 15 | std::cout << Dimensionality << "\n"; 16 | ListOfNumbers = new double[Dimensionality]; 17 | for (int i = 0; i < Dimensionality; ++i) { 18 | ListOfNumbers[i] = InputArray[i]; 19 | std::cout << ListOfNumbers[i] << ", "; 20 | } 21 | std::cout << "\n"; 22 | }; 23 | 24 | TestClass::~TestClass(void){ 25 | std::cout << "Being Destroyed" << "\n"; 26 | }; 27 | 28 | double TestClass::SumListOfNumbers(void){ 29 | double Sum = 0; 30 | for (int i = 0; i < Dimensionality; ++i) { 31 | Sum += ListOfNumbers[i]; 32 | } 33 | return Sum; 34 | } 35 | -------------------------------------------------------------------------------- /ClassCythonCPPWithMemberFunctions/makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python setup.py build_ext --inplace 3 | -------------------------------------------------------------------------------- /ClassCythonCPPWithMemberFunctions/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | from Cython.Build import cythonize 4 | import numpy 5 | 6 | ext = Extension('TestClass', sources=["TestClass.pyx"], language="c++", include_dirs=[numpy.get_include()]) 7 | 8 | setup(name="TestClass", ext_modules = cythonize([ext])) 9 | -------------------------------------------------------------------------------- /HelloWorld/helloworld.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "helloworldC.cpp": 2 | void Helloworld() 3 | 4 | def C_Helloworld(): 5 | Helloworld() 6 | 7 | #c_helloworld() 8 | -------------------------------------------------------------------------------- /HelloWorld/helloworldC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Helloworld(){ 4 | std::cout << "Hello world!" << "\n"; 5 | } 6 | -------------------------------------------------------------------------------- /HelloWorld/makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python setup.py build_ext --inplace 3 | -------------------------------------------------------------------------------- /HelloWorld/minimalRunScript.py: -------------------------------------------------------------------------------- 1 | import helloworld 2 | 3 | helloworld.C_Helloworld() 4 | -------------------------------------------------------------------------------- /HelloWorld/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | from Cython.Build import cythonize 4 | 5 | ext = Extension('helloworld', sources=["helloworld.pyx"], language="c++") 6 | 7 | setup(name="helloworld", ext_modules = cythonize([ext])) 8 | -------------------------------------------------------------------------------- /HelloWorldOpenMP/helloworld.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "helloworldC.cpp": 2 | void Helloworld() 3 | 4 | def C_Helloworld(): 5 | Helloworld() 6 | 7 | #c_helloworld() 8 | -------------------------------------------------------------------------------- /HelloWorldOpenMP/helloworldC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void Helloworld(){ 5 | #pragma omp parallel 6 | { 7 | int Thread_Num = omp_get_thread_num(); 8 | #pragma omp critical 9 | std::cout << "Hello world! from Thread " << Thread_Num << "\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HelloWorldOpenMP/makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python setup.py build_ext --inplace 3 | -------------------------------------------------------------------------------- /HelloWorldOpenMP/minimalRunScript.py: -------------------------------------------------------------------------------- 1 | import helloworld 2 | 3 | helloworld.C_Helloworld() 4 | -------------------------------------------------------------------------------- /HelloWorldOpenMP/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | from Cython.Build import cythonize 4 | 5 | ext = Extension('helloworld', sources=["helloworld.pyx"], language="c++", extra_compile_args=['-fopenmp'], extra_link_args=['-lgomp']) 6 | 7 | setup(name="helloworld", ext_modules = cythonize([ext])) 8 | -------------------------------------------------------------------------------- /KalmanFilterC/CythonExample.cpp: -------------------------------------------------------------------------------- 1 | /* Generated by Cython 0.25.2 */ 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 | #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) 8 | #error Cython requires Python 2.6+ or Python 3.2+. 9 | #else 10 | #define CYTHON_ABI "0_25_2" 11 | #include 12 | #ifndef offsetof 13 | #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) 14 | #endif 15 | #if !defined(WIN32) && !defined(MS_WINDOWS) 16 | #ifndef __stdcall 17 | #define __stdcall 18 | #endif 19 | #ifndef __cdecl 20 | #define __cdecl 21 | #endif 22 | #ifndef __fastcall 23 | #define __fastcall 24 | #endif 25 | #endif 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 | #ifndef HAVE_LONG_LONG 33 | #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000) 34 | #define HAVE_LONG_LONG 35 | #endif 36 | #endif 37 | #ifndef PY_LONG_LONG 38 | #define PY_LONG_LONG LONG_LONG 39 | #endif 40 | #ifndef Py_HUGE_VAL 41 | #define Py_HUGE_VAL HUGE_VAL 42 | #endif 43 | #ifdef PYPY_VERSION 44 | #define CYTHON_COMPILING_IN_PYPY 1 45 | #define CYTHON_COMPILING_IN_PYSTON 0 46 | #define CYTHON_COMPILING_IN_CPYTHON 0 47 | #undef CYTHON_USE_TYPE_SLOTS 48 | #define CYTHON_USE_TYPE_SLOTS 0 49 | #undef CYTHON_USE_ASYNC_SLOTS 50 | #define CYTHON_USE_ASYNC_SLOTS 0 51 | #undef CYTHON_USE_PYLIST_INTERNALS 52 | #define CYTHON_USE_PYLIST_INTERNALS 0 53 | #undef CYTHON_USE_UNICODE_INTERNALS 54 | #define CYTHON_USE_UNICODE_INTERNALS 0 55 | #undef CYTHON_USE_UNICODE_WRITER 56 | #define CYTHON_USE_UNICODE_WRITER 0 57 | #undef CYTHON_USE_PYLONG_INTERNALS 58 | #define CYTHON_USE_PYLONG_INTERNALS 0 59 | #undef CYTHON_AVOID_BORROWED_REFS 60 | #define CYTHON_AVOID_BORROWED_REFS 1 61 | #undef CYTHON_ASSUME_SAFE_MACROS 62 | #define CYTHON_ASSUME_SAFE_MACROS 0 63 | #undef CYTHON_UNPACK_METHODS 64 | #define CYTHON_UNPACK_METHODS 0 65 | #undef CYTHON_FAST_THREAD_STATE 66 | #define CYTHON_FAST_THREAD_STATE 0 67 | #undef CYTHON_FAST_PYCALL 68 | #define CYTHON_FAST_PYCALL 0 69 | #elif defined(PYSTON_VERSION) 70 | #define CYTHON_COMPILING_IN_PYPY 0 71 | #define CYTHON_COMPILING_IN_PYSTON 1 72 | #define CYTHON_COMPILING_IN_CPYTHON 0 73 | #ifndef CYTHON_USE_TYPE_SLOTS 74 | #define CYTHON_USE_TYPE_SLOTS 1 75 | #endif 76 | #undef CYTHON_USE_ASYNC_SLOTS 77 | #define CYTHON_USE_ASYNC_SLOTS 0 78 | #undef CYTHON_USE_PYLIST_INTERNALS 79 | #define CYTHON_USE_PYLIST_INTERNALS 0 80 | #ifndef CYTHON_USE_UNICODE_INTERNALS 81 | #define CYTHON_USE_UNICODE_INTERNALS 1 82 | #endif 83 | #undef CYTHON_USE_UNICODE_WRITER 84 | #define CYTHON_USE_UNICODE_WRITER 0 85 | #undef CYTHON_USE_PYLONG_INTERNALS 86 | #define CYTHON_USE_PYLONG_INTERNALS 0 87 | #ifndef CYTHON_AVOID_BORROWED_REFS 88 | #define CYTHON_AVOID_BORROWED_REFS 0 89 | #endif 90 | #ifndef CYTHON_ASSUME_SAFE_MACROS 91 | #define CYTHON_ASSUME_SAFE_MACROS 1 92 | #endif 93 | #ifndef CYTHON_UNPACK_METHODS 94 | #define CYTHON_UNPACK_METHODS 1 95 | #endif 96 | #undef CYTHON_FAST_THREAD_STATE 97 | #define CYTHON_FAST_THREAD_STATE 0 98 | #undef CYTHON_FAST_PYCALL 99 | #define CYTHON_FAST_PYCALL 0 100 | #else 101 | #define CYTHON_COMPILING_IN_PYPY 0 102 | #define CYTHON_COMPILING_IN_PYSTON 0 103 | #define CYTHON_COMPILING_IN_CPYTHON 1 104 | #ifndef CYTHON_USE_TYPE_SLOTS 105 | #define CYTHON_USE_TYPE_SLOTS 1 106 | #endif 107 | #if PY_MAJOR_VERSION < 3 108 | #undef CYTHON_USE_ASYNC_SLOTS 109 | #define CYTHON_USE_ASYNC_SLOTS 0 110 | #elif !defined(CYTHON_USE_ASYNC_SLOTS) 111 | #define CYTHON_USE_ASYNC_SLOTS 1 112 | #endif 113 | #if PY_VERSION_HEX < 0x02070000 114 | #undef CYTHON_USE_PYLONG_INTERNALS 115 | #define CYTHON_USE_PYLONG_INTERNALS 0 116 | #elif !defined(CYTHON_USE_PYLONG_INTERNALS) 117 | #define CYTHON_USE_PYLONG_INTERNALS 1 118 | #endif 119 | #ifndef CYTHON_USE_PYLIST_INTERNALS 120 | #define CYTHON_USE_PYLIST_INTERNALS 1 121 | #endif 122 | #ifndef CYTHON_USE_UNICODE_INTERNALS 123 | #define CYTHON_USE_UNICODE_INTERNALS 1 124 | #endif 125 | #if PY_VERSION_HEX < 0x030300F0 126 | #undef CYTHON_USE_UNICODE_WRITER 127 | #define CYTHON_USE_UNICODE_WRITER 0 128 | #elif !defined(CYTHON_USE_UNICODE_WRITER) 129 | #define CYTHON_USE_UNICODE_WRITER 1 130 | #endif 131 | #ifndef CYTHON_AVOID_BORROWED_REFS 132 | #define CYTHON_AVOID_BORROWED_REFS 0 133 | #endif 134 | #ifndef CYTHON_ASSUME_SAFE_MACROS 135 | #define CYTHON_ASSUME_SAFE_MACROS 1 136 | #endif 137 | #ifndef CYTHON_UNPACK_METHODS 138 | #define CYTHON_UNPACK_METHODS 1 139 | #endif 140 | #ifndef CYTHON_FAST_THREAD_STATE 141 | #define CYTHON_FAST_THREAD_STATE 1 142 | #endif 143 | #ifndef CYTHON_FAST_PYCALL 144 | #define CYTHON_FAST_PYCALL 1 145 | #endif 146 | #endif 147 | #if !defined(CYTHON_FAST_PYCCALL) 148 | #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) 149 | #endif 150 | #if CYTHON_USE_PYLONG_INTERNALS 151 | #include "longintrepr.h" 152 | #undef SHIFT 153 | #undef BASE 154 | #undef MASK 155 | #endif 156 | #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) 157 | #define Py_OptimizeFlag 0 158 | #endif 159 | #define __PYX_BUILD_PY_SSIZE_T "n" 160 | #define CYTHON_FORMAT_SSIZE_T "z" 161 | #if PY_MAJOR_VERSION < 3 162 | #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" 163 | #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ 164 | PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) 165 | #define __Pyx_DefaultClassType PyClass_Type 166 | #else 167 | #define __Pyx_BUILTIN_MODULE_NAME "builtins" 168 | #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ 169 | PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) 170 | #define __Pyx_DefaultClassType PyType_Type 171 | #endif 172 | #ifndef Py_TPFLAGS_CHECKTYPES 173 | #define Py_TPFLAGS_CHECKTYPES 0 174 | #endif 175 | #ifndef Py_TPFLAGS_HAVE_INDEX 176 | #define Py_TPFLAGS_HAVE_INDEX 0 177 | #endif 178 | #ifndef Py_TPFLAGS_HAVE_NEWBUFFER 179 | #define Py_TPFLAGS_HAVE_NEWBUFFER 0 180 | #endif 181 | #ifndef Py_TPFLAGS_HAVE_FINALIZE 182 | #define Py_TPFLAGS_HAVE_FINALIZE 0 183 | #endif 184 | #ifndef METH_FASTCALL 185 | #define METH_FASTCALL 0x80 186 | typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args, 187 | Py_ssize_t nargs, PyObject *kwnames); 188 | #else 189 | #define __Pyx_PyCFunctionFast _PyCFunctionFast 190 | #endif 191 | #if CYTHON_FAST_PYCCALL 192 | #define __Pyx_PyFastCFunction_Check(func)\ 193 | ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST))))) 194 | #else 195 | #define __Pyx_PyFastCFunction_Check(func) 0 196 | #endif 197 | #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) 198 | #define CYTHON_PEP393_ENABLED 1 199 | #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 200 | 0 : _PyUnicode_Ready((PyObject *)(op))) 201 | #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) 202 | #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) 203 | #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) 204 | #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) 205 | #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) 206 | #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) 207 | #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) 208 | #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) 209 | #else 210 | #define CYTHON_PEP393_ENABLED 0 211 | #define PyUnicode_1BYTE_KIND 1 212 | #define PyUnicode_2BYTE_KIND 2 213 | #define PyUnicode_4BYTE_KIND 4 214 | #define __Pyx_PyUnicode_READY(op) (0) 215 | #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) 216 | #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) 217 | #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) 218 | #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) 219 | #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) 220 | #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) 221 | #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) 222 | #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) 223 | #endif 224 | #if CYTHON_COMPILING_IN_PYPY 225 | #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) 226 | #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) 227 | #else 228 | #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) 229 | #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ 230 | PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) 231 | #endif 232 | #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) 233 | #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) 234 | #endif 235 | #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) 236 | #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) 237 | #endif 238 | #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) 239 | #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) 240 | #endif 241 | #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) 242 | #define PyObject_Malloc(s) PyMem_Malloc(s) 243 | #define PyObject_Free(p) PyMem_Free(p) 244 | #define PyObject_Realloc(p) PyMem_Realloc(p) 245 | #endif 246 | #if CYTHON_COMPILING_IN_PYSTON 247 | #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) 248 | #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) 249 | #else 250 | #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) 251 | #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) 252 | #endif 253 | #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) 254 | #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) 255 | #if PY_MAJOR_VERSION >= 3 256 | #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) 257 | #else 258 | #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) 259 | #endif 260 | #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) 261 | #define PyObject_ASCII(o) PyObject_Repr(o) 262 | #endif 263 | #if PY_MAJOR_VERSION >= 3 264 | #define PyBaseString_Type PyUnicode_Type 265 | #define PyStringObject PyUnicodeObject 266 | #define PyString_Type PyUnicode_Type 267 | #define PyString_Check PyUnicode_Check 268 | #define PyString_CheckExact PyUnicode_CheckExact 269 | #endif 270 | #if PY_MAJOR_VERSION >= 3 271 | #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) 272 | #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) 273 | #else 274 | #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) 275 | #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) 276 | #endif 277 | #ifndef PySet_CheckExact 278 | #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) 279 | #endif 280 | #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) 281 | #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) 282 | #if PY_MAJOR_VERSION >= 3 283 | #define PyIntObject PyLongObject 284 | #define PyInt_Type PyLong_Type 285 | #define PyInt_Check(op) PyLong_Check(op) 286 | #define PyInt_CheckExact(op) PyLong_CheckExact(op) 287 | #define PyInt_FromString PyLong_FromString 288 | #define PyInt_FromUnicode PyLong_FromUnicode 289 | #define PyInt_FromLong PyLong_FromLong 290 | #define PyInt_FromSize_t PyLong_FromSize_t 291 | #define PyInt_FromSsize_t PyLong_FromSsize_t 292 | #define PyInt_AsLong PyLong_AsLong 293 | #define PyInt_AS_LONG PyLong_AS_LONG 294 | #define PyInt_AsSsize_t PyLong_AsSsize_t 295 | #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask 296 | #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask 297 | #define PyNumber_Int PyNumber_Long 298 | #endif 299 | #if PY_MAJOR_VERSION >= 3 300 | #define PyBoolObject PyLongObject 301 | #endif 302 | #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY 303 | #ifndef PyUnicode_InternFromString 304 | #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) 305 | #endif 306 | #endif 307 | #if PY_VERSION_HEX < 0x030200A4 308 | typedef long Py_hash_t; 309 | #define __Pyx_PyInt_FromHash_t PyInt_FromLong 310 | #define __Pyx_PyInt_AsHash_t PyInt_AsLong 311 | #else 312 | #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t 313 | #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t 314 | #endif 315 | #if PY_MAJOR_VERSION >= 3 316 | #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) 317 | #else 318 | #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) 319 | #endif 320 | #if CYTHON_USE_ASYNC_SLOTS 321 | #if PY_VERSION_HEX >= 0x030500B1 322 | #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods 323 | #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) 324 | #else 325 | typedef struct { 326 | unaryfunc am_await; 327 | unaryfunc am_aiter; 328 | unaryfunc am_anext; 329 | } __Pyx_PyAsyncMethodsStruct; 330 | #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) 331 | #endif 332 | #else 333 | #define __Pyx_PyType_AsAsync(obj) NULL 334 | #endif 335 | #ifndef CYTHON_RESTRICT 336 | #if defined(__GNUC__) 337 | #define CYTHON_RESTRICT __restrict__ 338 | #elif defined(_MSC_VER) && _MSC_VER >= 1400 339 | #define CYTHON_RESTRICT __restrict 340 | #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 341 | #define CYTHON_RESTRICT restrict 342 | #else 343 | #define CYTHON_RESTRICT 344 | #endif 345 | #endif 346 | #ifndef CYTHON_UNUSED 347 | # if defined(__GNUC__) 348 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 349 | # define CYTHON_UNUSED __attribute__ ((__unused__)) 350 | # else 351 | # define CYTHON_UNUSED 352 | # endif 353 | # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) 354 | # define CYTHON_UNUSED __attribute__ ((__unused__)) 355 | # else 356 | # define CYTHON_UNUSED 357 | # endif 358 | #endif 359 | #ifndef CYTHON_MAYBE_UNUSED_VAR 360 | # if defined(__cplusplus) 361 | template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } 362 | # else 363 | # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) 364 | # endif 365 | #endif 366 | #ifndef CYTHON_NCP_UNUSED 367 | # if CYTHON_COMPILING_IN_CPYTHON 368 | # define CYTHON_NCP_UNUSED 369 | # else 370 | # define CYTHON_NCP_UNUSED CYTHON_UNUSED 371 | # endif 372 | #endif 373 | #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) 374 | 375 | #ifndef __cplusplus 376 | #error "Cython files generated with the C++ option must be compiled with a C++ compiler." 377 | #endif 378 | #ifndef CYTHON_INLINE 379 | #if defined(__clang__) 380 | #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) 381 | #else 382 | #define CYTHON_INLINE inline 383 | #endif 384 | #endif 385 | template 386 | void __Pyx_call_destructor(T& x) { 387 | x.~T(); 388 | } 389 | template 390 | class __Pyx_FakeReference { 391 | public: 392 | __Pyx_FakeReference() : ptr(NULL) { } 393 | __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } 394 | T *operator->() { return ptr; } 395 | T *operator&() { return ptr; } 396 | operator T&() { return *ptr; } 397 | template bool operator ==(U other) { return *ptr == other; } 398 | template bool operator !=(U other) { return *ptr != other; } 399 | private: 400 | T *ptr; 401 | }; 402 | 403 | #if defined(WIN32) || defined(MS_WINDOWS) 404 | #define _USE_MATH_DEFINES 405 | #endif 406 | #include 407 | #ifdef NAN 408 | #define __PYX_NAN() ((float) NAN) 409 | #else 410 | static CYTHON_INLINE float __PYX_NAN() { 411 | float value; 412 | memset(&value, 0xFF, sizeof(value)); 413 | return value; 414 | } 415 | #endif 416 | #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) 417 | #define __Pyx_truncl trunc 418 | #else 419 | #define __Pyx_truncl truncl 420 | #endif 421 | 422 | 423 | #define __PYX_ERR(f_index, lineno, Ln_error) \ 424 | { \ 425 | __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ 426 | } 427 | 428 | #if PY_MAJOR_VERSION >= 3 429 | #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) 430 | #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) 431 | #else 432 | #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) 433 | #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) 434 | #endif 435 | 436 | #ifndef __PYX_EXTERN_C 437 | #ifdef __cplusplus 438 | #define __PYX_EXTERN_C extern "C" 439 | #else 440 | #define __PYX_EXTERN_C extern 441 | #endif 442 | #endif 443 | 444 | #define __PYX_HAVE__test 445 | #define __PYX_HAVE_API__test 446 | #include "cpp_test.h" 447 | #ifdef _OPENMP 448 | #include 449 | #endif /* _OPENMP */ 450 | 451 | #ifdef PYREX_WITHOUT_ASSERTIONS 452 | #define CYTHON_WITHOUT_ASSERTIONS 453 | #endif 454 | 455 | typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; 456 | const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; 457 | 458 | #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 459 | #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 460 | #define __PYX_DEFAULT_STRING_ENCODING "" 461 | #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString 462 | #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize 463 | #define __Pyx_uchar_cast(c) ((unsigned char)c) 464 | #define __Pyx_long_cast(x) ((long)x) 465 | #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ 466 | (sizeof(type) < sizeof(Py_ssize_t)) ||\ 467 | (sizeof(type) > sizeof(Py_ssize_t) &&\ 468 | likely(v < (type)PY_SSIZE_T_MAX ||\ 469 | v == (type)PY_SSIZE_T_MAX) &&\ 470 | (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ 471 | v == (type)PY_SSIZE_T_MIN))) ||\ 472 | (sizeof(type) == sizeof(Py_ssize_t) &&\ 473 | (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ 474 | v == (type)PY_SSIZE_T_MAX))) ) 475 | #if defined (__cplusplus) && __cplusplus >= 201103L 476 | #include 477 | #define __Pyx_sst_abs(value) std::abs(value) 478 | #elif SIZEOF_INT >= SIZEOF_SIZE_T 479 | #define __Pyx_sst_abs(value) abs(value) 480 | #elif SIZEOF_LONG >= SIZEOF_SIZE_T 481 | #define __Pyx_sst_abs(value) labs(value) 482 | #elif defined (_MSC_VER) && defined (_M_X64) 483 | #define __Pyx_sst_abs(value) _abs64(value) 484 | #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 485 | #define __Pyx_sst_abs(value) llabs(value) 486 | #elif defined (__GNUC__) 487 | #define __Pyx_sst_abs(value) __builtin_llabs(value) 488 | #else 489 | #define __Pyx_sst_abs(value) ((value<0) ? -value : value) 490 | #endif 491 | static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); 492 | static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); 493 | #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) 494 | #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) 495 | #define __Pyx_PyBytes_FromString PyBytes_FromString 496 | #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize 497 | static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); 498 | #if PY_MAJOR_VERSION < 3 499 | #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString 500 | #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize 501 | #else 502 | #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString 503 | #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize 504 | #endif 505 | #define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) 506 | #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) 507 | #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) 508 | #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) 509 | #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) 510 | #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) 511 | #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) 512 | #if PY_MAJOR_VERSION < 3 513 | static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) 514 | { 515 | const Py_UNICODE *u_end = u; 516 | while (*u_end++) ; 517 | return (size_t)(u_end - u - 1); 518 | } 519 | #else 520 | #define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen 521 | #endif 522 | #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) 523 | #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode 524 | #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode 525 | #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) 526 | #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) 527 | #define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) 528 | static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); 529 | static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); 530 | static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); 531 | static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); 532 | #if CYTHON_ASSUME_SAFE_MACROS 533 | #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) 534 | #else 535 | #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) 536 | #endif 537 | #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) 538 | #if PY_MAJOR_VERSION >= 3 539 | #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) 540 | #else 541 | #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) 542 | #endif 543 | #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) 544 | #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 545 | static int __Pyx_sys_getdefaultencoding_not_ascii; 546 | static int __Pyx_init_sys_getdefaultencoding_params(void) { 547 | PyObject* sys; 548 | PyObject* default_encoding = NULL; 549 | PyObject* ascii_chars_u = NULL; 550 | PyObject* ascii_chars_b = NULL; 551 | const char* default_encoding_c; 552 | sys = PyImport_ImportModule("sys"); 553 | if (!sys) goto bad; 554 | default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); 555 | Py_DECREF(sys); 556 | if (!default_encoding) goto bad; 557 | default_encoding_c = PyBytes_AsString(default_encoding); 558 | if (!default_encoding_c) goto bad; 559 | if (strcmp(default_encoding_c, "ascii") == 0) { 560 | __Pyx_sys_getdefaultencoding_not_ascii = 0; 561 | } else { 562 | char ascii_chars[128]; 563 | int c; 564 | for (c = 0; c < 128; c++) { 565 | ascii_chars[c] = c; 566 | } 567 | __Pyx_sys_getdefaultencoding_not_ascii = 1; 568 | ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); 569 | if (!ascii_chars_u) goto bad; 570 | ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); 571 | if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { 572 | PyErr_Format( 573 | PyExc_ValueError, 574 | "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", 575 | default_encoding_c); 576 | goto bad; 577 | } 578 | Py_DECREF(ascii_chars_u); 579 | Py_DECREF(ascii_chars_b); 580 | } 581 | Py_DECREF(default_encoding); 582 | return 0; 583 | bad: 584 | Py_XDECREF(default_encoding); 585 | Py_XDECREF(ascii_chars_u); 586 | Py_XDECREF(ascii_chars_b); 587 | return -1; 588 | } 589 | #endif 590 | #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 591 | #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) 592 | #else 593 | #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) 594 | #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 595 | static char* __PYX_DEFAULT_STRING_ENCODING; 596 | static int __Pyx_init_sys_getdefaultencoding_params(void) { 597 | PyObject* sys; 598 | PyObject* default_encoding = NULL; 599 | char* default_encoding_c; 600 | sys = PyImport_ImportModule("sys"); 601 | if (!sys) goto bad; 602 | default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); 603 | Py_DECREF(sys); 604 | if (!default_encoding) goto bad; 605 | default_encoding_c = PyBytes_AsString(default_encoding); 606 | if (!default_encoding_c) goto bad; 607 | __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); 608 | if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; 609 | strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); 610 | Py_DECREF(default_encoding); 611 | return 0; 612 | bad: 613 | Py_XDECREF(default_encoding); 614 | return -1; 615 | } 616 | #endif 617 | #endif 618 | 619 | 620 | /* Test for GCC > 2.95 */ 621 | #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) 622 | #define likely(x) __builtin_expect(!!(x), 1) 623 | #define unlikely(x) __builtin_expect(!!(x), 0) 624 | #else /* !__GNUC__ or GCC < 2.95 */ 625 | #define likely(x) (x) 626 | #define unlikely(x) (x) 627 | #endif /* __GNUC__ */ 628 | 629 | static PyObject *__pyx_m; 630 | static PyObject *__pyx_d; 631 | static PyObject *__pyx_b; 632 | static PyObject *__pyx_empty_tuple; 633 | static PyObject *__pyx_empty_bytes; 634 | static PyObject *__pyx_empty_unicode; 635 | static int __pyx_lineno; 636 | static int __pyx_clineno = 0; 637 | static const char * __pyx_cfilenm= __FILE__; 638 | static const char *__pyx_filename; 639 | 640 | 641 | static const char *__pyx_f[] = { 642 | "CythonExample.pyx", 643 | }; 644 | 645 | /*--- Type declarations ---*/ 646 | struct __pyx_obj_4test_pyTest; 647 | 648 | /* "CythonExample.pyx":10 649 | * Test sub "operator-"(Test other) 650 | * 651 | * cdef class pyTest: # <<<<<<<<<<<<<< 652 | * cdef Test* thisptr # hold a C++ instance 653 | * def __cinit__(self, int test1): 654 | */ 655 | struct __pyx_obj_4test_pyTest { 656 | PyObject_HEAD 657 | Test *thisptr; 658 | }; 659 | 660 | 661 | /* --- Runtime support code (head) --- */ 662 | /* Refnanny.proto */ 663 | #ifndef CYTHON_REFNANNY 664 | #define CYTHON_REFNANNY 0 665 | #endif 666 | #if CYTHON_REFNANNY 667 | typedef struct { 668 | void (*INCREF)(void*, PyObject*, int); 669 | void (*DECREF)(void*, PyObject*, int); 670 | void (*GOTREF)(void*, PyObject*, int); 671 | void (*GIVEREF)(void*, PyObject*, int); 672 | void* (*SetupContext)(const char*, int, const char*); 673 | void (*FinishContext)(void**); 674 | } __Pyx_RefNannyAPIStruct; 675 | static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; 676 | static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); 677 | #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; 678 | #ifdef WITH_THREAD 679 | #define __Pyx_RefNannySetupContext(name, acquire_gil)\ 680 | if (acquire_gil) {\ 681 | PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ 682 | __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ 683 | PyGILState_Release(__pyx_gilstate_save);\ 684 | } else {\ 685 | __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ 686 | } 687 | #else 688 | #define __Pyx_RefNannySetupContext(name, acquire_gil)\ 689 | __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) 690 | #endif 691 | #define __Pyx_RefNannyFinishContext()\ 692 | __Pyx_RefNanny->FinishContext(&__pyx_refnanny) 693 | #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) 694 | #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) 695 | #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) 696 | #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) 697 | #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) 698 | #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) 699 | #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) 700 | #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) 701 | #else 702 | #define __Pyx_RefNannyDeclarations 703 | #define __Pyx_RefNannySetupContext(name, acquire_gil) 704 | #define __Pyx_RefNannyFinishContext() 705 | #define __Pyx_INCREF(r) Py_INCREF(r) 706 | #define __Pyx_DECREF(r) Py_DECREF(r) 707 | #define __Pyx_GOTREF(r) 708 | #define __Pyx_GIVEREF(r) 709 | #define __Pyx_XINCREF(r) Py_XINCREF(r) 710 | #define __Pyx_XDECREF(r) Py_XDECREF(r) 711 | #define __Pyx_XGOTREF(r) 712 | #define __Pyx_XGIVEREF(r) 713 | #endif 714 | #define __Pyx_XDECREF_SET(r, v) do {\ 715 | PyObject *tmp = (PyObject *) r;\ 716 | r = v; __Pyx_XDECREF(tmp);\ 717 | } while (0) 718 | #define __Pyx_DECREF_SET(r, v) do {\ 719 | PyObject *tmp = (PyObject *) r;\ 720 | r = v; __Pyx_DECREF(tmp);\ 721 | } while (0) 722 | #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) 723 | #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) 724 | 725 | /* RaiseDoubleKeywords.proto */ 726 | static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); 727 | 728 | /* ParseKeywords.proto */ 729 | static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ 730 | PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ 731 | const char* function_name); 732 | 733 | /* RaiseArgTupleInvalid.proto */ 734 | static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, 735 | Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); 736 | 737 | /* ArgTypeTest.proto */ 738 | static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, 739 | const char *name, int exact); 740 | 741 | /* PyObjectCall.proto */ 742 | #if CYTHON_COMPILING_IN_CPYTHON 743 | static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); 744 | #else 745 | #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) 746 | #endif 747 | 748 | /* CodeObjectCache.proto */ 749 | typedef struct { 750 | PyCodeObject* code_object; 751 | int code_line; 752 | } __Pyx_CodeObjectCacheEntry; 753 | struct __Pyx_CodeObjectCache { 754 | int count; 755 | int max_count; 756 | __Pyx_CodeObjectCacheEntry* entries; 757 | }; 758 | static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; 759 | static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); 760 | static PyCodeObject *__pyx_find_code_object(int code_line); 761 | static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); 762 | 763 | /* AddTraceback.proto */ 764 | static void __Pyx_AddTraceback(const char *funcname, int c_line, 765 | int py_line, const char *filename); 766 | 767 | /* CIntToPy.proto */ 768 | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); 769 | 770 | /* CIntFromPy.proto */ 771 | static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); 772 | 773 | /* CIntToPy.proto */ 774 | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); 775 | 776 | /* CIntFromPy.proto */ 777 | static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); 778 | 779 | /* CheckBinaryVersion.proto */ 780 | static int __Pyx_check_binary_version(void); 781 | 782 | /* InitStrings.proto */ 783 | static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); 784 | 785 | 786 | /* Module declarations from 'test' */ 787 | static PyTypeObject *__pyx_ptype_4test_pyTest = 0; 788 | #define __Pyx_MODULE_NAME "test" 789 | int __pyx_module_is_main_test = 0; 790 | 791 | /* Implementation of 'test' */ 792 | static const char __pyx_k_main[] = "__main__"; 793 | static const char __pyx_k_test[] = "__test__"; 794 | static const char __pyx_k_test1[] = "test1"; 795 | static const char __pyx_k_pyTest_s[] = "pyTest[%s]"; 796 | static const char __pyx_k_hello_world[] = "hello world"; 797 | static PyObject *__pyx_kp_s_hello_world; 798 | static PyObject *__pyx_n_s_main; 799 | static PyObject *__pyx_kp_s_pyTest_s; 800 | static PyObject *__pyx_n_s_test; 801 | static PyObject *__pyx_n_s_test1; 802 | static int __pyx_pf_4test_6pyTest___cinit__(struct __pyx_obj_4test_pyTest *__pyx_v_self, int __pyx_v_test1); /* proto */ 803 | static void __pyx_pf_4test_6pyTest_2__dealloc__(struct __pyx_obj_4test_pyTest *__pyx_v_self); /* proto */ 804 | static PyObject *__pyx_pf_4test_6pyTest_4__add__(struct __pyx_obj_4test_pyTest *__pyx_v_left, struct __pyx_obj_4test_pyTest *__pyx_v_other); /* proto */ 805 | static PyObject *__pyx_pf_4test_6pyTest_6__sub__(struct __pyx_obj_4test_pyTest *__pyx_v_left, struct __pyx_obj_4test_pyTest *__pyx_v_other); /* proto */ 806 | static PyObject *__pyx_pf_4test_6pyTest_8__repr__(struct __pyx_obj_4test_pyTest *__pyx_v_self); /* proto */ 807 | static PyObject *__pyx_pf_4test_6pyTest_10returnFive(struct __pyx_obj_4test_pyTest *__pyx_v_self); /* proto */ 808 | static PyObject *__pyx_pf_4test_6pyTest_12printMe(CYTHON_UNUSED struct __pyx_obj_4test_pyTest *__pyx_v_self); /* proto */ 809 | static PyObject *__pyx_tp_new_4test_pyTest(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ 810 | 811 | /* "CythonExample.pyx":12 812 | * cdef class pyTest: 813 | * cdef Test* thisptr # hold a C++ instance 814 | * def __cinit__(self, int test1): # <<<<<<<<<<<<<< 815 | * self.thisptr = new Test(test1) 816 | * def __dealloc__(self): 817 | */ 818 | 819 | /* Python wrapper */ 820 | static int __pyx_pw_4test_6pyTest_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ 821 | static int __pyx_pw_4test_6pyTest_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { 822 | int __pyx_v_test1; 823 | int __pyx_r; 824 | __Pyx_RefNannyDeclarations 825 | __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); 826 | { 827 | static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_test1,0}; 828 | PyObject* values[1] = {0}; 829 | if (unlikely(__pyx_kwds)) { 830 | Py_ssize_t kw_args; 831 | const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); 832 | switch (pos_args) { 833 | case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); 834 | case 0: break; 835 | default: goto __pyx_L5_argtuple_error; 836 | } 837 | kw_args = PyDict_Size(__pyx_kwds); 838 | switch (pos_args) { 839 | case 0: 840 | if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_test1)) != 0)) kw_args--; 841 | else goto __pyx_L5_argtuple_error; 842 | } 843 | if (unlikely(kw_args > 0)) { 844 | if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 12, __pyx_L3_error) 845 | } 846 | } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { 847 | goto __pyx_L5_argtuple_error; 848 | } else { 849 | values[0] = PyTuple_GET_ITEM(__pyx_args, 0); 850 | } 851 | __pyx_v_test1 = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_test1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L3_error) 852 | } 853 | goto __pyx_L4_argument_unpacking_done; 854 | __pyx_L5_argtuple_error:; 855 | __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 12, __pyx_L3_error) 856 | __pyx_L3_error:; 857 | __Pyx_AddTraceback("test.pyTest.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); 858 | __Pyx_RefNannyFinishContext(); 859 | return -1; 860 | __pyx_L4_argument_unpacking_done:; 861 | __pyx_r = __pyx_pf_4test_6pyTest___cinit__(((struct __pyx_obj_4test_pyTest *)__pyx_v_self), __pyx_v_test1); 862 | 863 | /* function exit code */ 864 | __Pyx_RefNannyFinishContext(); 865 | return __pyx_r; 866 | } 867 | 868 | static int __pyx_pf_4test_6pyTest___cinit__(struct __pyx_obj_4test_pyTest *__pyx_v_self, int __pyx_v_test1) { 869 | int __pyx_r; 870 | __Pyx_RefNannyDeclarations 871 | __Pyx_RefNannySetupContext("__cinit__", 0); 872 | 873 | /* "CythonExample.pyx":13 874 | * cdef Test* thisptr # hold a C++ instance 875 | * def __cinit__(self, int test1): 876 | * self.thisptr = new Test(test1) # <<<<<<<<<<<<<< 877 | * def __dealloc__(self): 878 | * del self.thisptr 879 | */ 880 | __pyx_v_self->thisptr = new Test(__pyx_v_test1); 881 | 882 | /* "CythonExample.pyx":12 883 | * cdef class pyTest: 884 | * cdef Test* thisptr # hold a C++ instance 885 | * def __cinit__(self, int test1): # <<<<<<<<<<<<<< 886 | * self.thisptr = new Test(test1) 887 | * def __dealloc__(self): 888 | */ 889 | 890 | /* function exit code */ 891 | __pyx_r = 0; 892 | __Pyx_RefNannyFinishContext(); 893 | return __pyx_r; 894 | } 895 | 896 | /* "CythonExample.pyx":14 897 | * def __cinit__(self, int test1): 898 | * self.thisptr = new Test(test1) 899 | * def __dealloc__(self): # <<<<<<<<<<<<<< 900 | * del self.thisptr 901 | * 902 | */ 903 | 904 | /* Python wrapper */ 905 | static void __pyx_pw_4test_6pyTest_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ 906 | static void __pyx_pw_4test_6pyTest_3__dealloc__(PyObject *__pyx_v_self) { 907 | __Pyx_RefNannyDeclarations 908 | __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); 909 | __pyx_pf_4test_6pyTest_2__dealloc__(((struct __pyx_obj_4test_pyTest *)__pyx_v_self)); 910 | 911 | /* function exit code */ 912 | __Pyx_RefNannyFinishContext(); 913 | } 914 | 915 | static void __pyx_pf_4test_6pyTest_2__dealloc__(struct __pyx_obj_4test_pyTest *__pyx_v_self) { 916 | __Pyx_RefNannyDeclarations 917 | __Pyx_RefNannySetupContext("__dealloc__", 0); 918 | 919 | /* "CythonExample.pyx":15 920 | * self.thisptr = new Test(test1) 921 | * def __dealloc__(self): 922 | * del self.thisptr # <<<<<<<<<<<<<< 923 | * 924 | * def __add__(pyTest left, pyTest other): 925 | */ 926 | delete __pyx_v_self->thisptr; 927 | 928 | /* "CythonExample.pyx":14 929 | * def __cinit__(self, int test1): 930 | * self.thisptr = new Test(test1) 931 | * def __dealloc__(self): # <<<<<<<<<<<<<< 932 | * del self.thisptr 933 | * 934 | */ 935 | 936 | /* function exit code */ 937 | __Pyx_RefNannyFinishContext(); 938 | } 939 | 940 | /* "CythonExample.pyx":17 941 | * del self.thisptr 942 | * 943 | * def __add__(pyTest left, pyTest other): # <<<<<<<<<<<<<< 944 | * cdef Test t = left.thisptr.add(other.thisptr[0]) 945 | * cdef pyTest tt = pyTest(t.test1) 946 | */ 947 | 948 | /* Python wrapper */ 949 | static PyObject *__pyx_pw_4test_6pyTest_5__add__(PyObject *__pyx_v_left, PyObject *__pyx_v_other); /*proto*/ 950 | static PyObject *__pyx_pw_4test_6pyTest_5__add__(PyObject *__pyx_v_left, PyObject *__pyx_v_other) { 951 | PyObject *__pyx_r = 0; 952 | __Pyx_RefNannyDeclarations 953 | __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); 954 | if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left), __pyx_ptype_4test_pyTest, 1, "left", 0))) __PYX_ERR(0, 17, __pyx_L1_error) 955 | if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_4test_pyTest, 1, "other", 0))) __PYX_ERR(0, 17, __pyx_L1_error) 956 | __pyx_r = __pyx_pf_4test_6pyTest_4__add__(((struct __pyx_obj_4test_pyTest *)__pyx_v_left), ((struct __pyx_obj_4test_pyTest *)__pyx_v_other)); 957 | 958 | /* function exit code */ 959 | goto __pyx_L0; 960 | __pyx_L1_error:; 961 | __pyx_r = NULL; 962 | __pyx_L0:; 963 | __Pyx_RefNannyFinishContext(); 964 | return __pyx_r; 965 | } 966 | 967 | static PyObject *__pyx_pf_4test_6pyTest_4__add__(struct __pyx_obj_4test_pyTest *__pyx_v_left, struct __pyx_obj_4test_pyTest *__pyx_v_other) { 968 | Test __pyx_v_t; 969 | struct __pyx_obj_4test_pyTest *__pyx_v_tt = 0; 970 | PyObject *__pyx_r = NULL; 971 | __Pyx_RefNannyDeclarations 972 | PyObject *__pyx_t_1 = NULL; 973 | PyObject *__pyx_t_2 = NULL; 974 | __Pyx_RefNannySetupContext("__add__", 0); 975 | 976 | /* "CythonExample.pyx":18 977 | * 978 | * def __add__(pyTest left, pyTest other): 979 | * cdef Test t = left.thisptr.add(other.thisptr[0]) # <<<<<<<<<<<<<< 980 | * cdef pyTest tt = pyTest(t.test1) 981 | * return tt 982 | */ 983 | __pyx_v_t = __pyx_v_left->thisptr->operator+((__pyx_v_other->thisptr[0])); 984 | 985 | /* "CythonExample.pyx":19 986 | * def __add__(pyTest left, pyTest other): 987 | * cdef Test t = left.thisptr.add(other.thisptr[0]) 988 | * cdef pyTest tt = pyTest(t.test1) # <<<<<<<<<<<<<< 989 | * return tt 990 | * def __sub__(pyTest left, pyTest other): 991 | */ 992 | __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_t.test1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error) 993 | __Pyx_GOTREF(__pyx_t_1); 994 | __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error) 995 | __Pyx_GOTREF(__pyx_t_2); 996 | __Pyx_GIVEREF(__pyx_t_1); 997 | PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); 998 | __pyx_t_1 = 0; 999 | __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4test_pyTest), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error) 1000 | __Pyx_GOTREF(__pyx_t_1); 1001 | __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; 1002 | __pyx_v_tt = ((struct __pyx_obj_4test_pyTest *)__pyx_t_1); 1003 | __pyx_t_1 = 0; 1004 | 1005 | /* "CythonExample.pyx":20 1006 | * cdef Test t = left.thisptr.add(other.thisptr[0]) 1007 | * cdef pyTest tt = pyTest(t.test1) 1008 | * return tt # <<<<<<<<<<<<<< 1009 | * def __sub__(pyTest left, pyTest other): 1010 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) 1011 | */ 1012 | __Pyx_XDECREF(__pyx_r); 1013 | __Pyx_INCREF(((PyObject *)__pyx_v_tt)); 1014 | __pyx_r = ((PyObject *)__pyx_v_tt); 1015 | goto __pyx_L0; 1016 | 1017 | /* "CythonExample.pyx":17 1018 | * del self.thisptr 1019 | * 1020 | * def __add__(pyTest left, pyTest other): # <<<<<<<<<<<<<< 1021 | * cdef Test t = left.thisptr.add(other.thisptr[0]) 1022 | * cdef pyTest tt = pyTest(t.test1) 1023 | */ 1024 | 1025 | /* function exit code */ 1026 | __pyx_L1_error:; 1027 | __Pyx_XDECREF(__pyx_t_1); 1028 | __Pyx_XDECREF(__pyx_t_2); 1029 | __Pyx_AddTraceback("test.pyTest.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); 1030 | __pyx_r = NULL; 1031 | __pyx_L0:; 1032 | __Pyx_XDECREF((PyObject *)__pyx_v_tt); 1033 | __Pyx_XGIVEREF(__pyx_r); 1034 | __Pyx_RefNannyFinishContext(); 1035 | return __pyx_r; 1036 | } 1037 | 1038 | /* "CythonExample.pyx":21 1039 | * cdef pyTest tt = pyTest(t.test1) 1040 | * return tt 1041 | * def __sub__(pyTest left, pyTest other): # <<<<<<<<<<<<<< 1042 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) 1043 | * cdef pyTest tt = pyTest(t.test1) 1044 | */ 1045 | 1046 | /* Python wrapper */ 1047 | static PyObject *__pyx_pw_4test_6pyTest_7__sub__(PyObject *__pyx_v_left, PyObject *__pyx_v_other); /*proto*/ 1048 | static PyObject *__pyx_pw_4test_6pyTest_7__sub__(PyObject *__pyx_v_left, PyObject *__pyx_v_other) { 1049 | PyObject *__pyx_r = 0; 1050 | __Pyx_RefNannyDeclarations 1051 | __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); 1052 | if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left), __pyx_ptype_4test_pyTest, 1, "left", 0))) __PYX_ERR(0, 21, __pyx_L1_error) 1053 | if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_4test_pyTest, 1, "other", 0))) __PYX_ERR(0, 21, __pyx_L1_error) 1054 | __pyx_r = __pyx_pf_4test_6pyTest_6__sub__(((struct __pyx_obj_4test_pyTest *)__pyx_v_left), ((struct __pyx_obj_4test_pyTest *)__pyx_v_other)); 1055 | 1056 | /* function exit code */ 1057 | goto __pyx_L0; 1058 | __pyx_L1_error:; 1059 | __pyx_r = NULL; 1060 | __pyx_L0:; 1061 | __Pyx_RefNannyFinishContext(); 1062 | return __pyx_r; 1063 | } 1064 | 1065 | static PyObject *__pyx_pf_4test_6pyTest_6__sub__(struct __pyx_obj_4test_pyTest *__pyx_v_left, struct __pyx_obj_4test_pyTest *__pyx_v_other) { 1066 | Test __pyx_v_t; 1067 | struct __pyx_obj_4test_pyTest *__pyx_v_tt = 0; 1068 | PyObject *__pyx_r = NULL; 1069 | __Pyx_RefNannyDeclarations 1070 | PyObject *__pyx_t_1 = NULL; 1071 | PyObject *__pyx_t_2 = NULL; 1072 | __Pyx_RefNannySetupContext("__sub__", 0); 1073 | 1074 | /* "CythonExample.pyx":22 1075 | * return tt 1076 | * def __sub__(pyTest left, pyTest other): 1077 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) # <<<<<<<<<<<<<< 1078 | * cdef pyTest tt = pyTest(t.test1) 1079 | * return tt 1080 | */ 1081 | __pyx_v_t = __pyx_v_left->thisptr->operator-((__pyx_v_other->thisptr[0])); 1082 | 1083 | /* "CythonExample.pyx":23 1084 | * def __sub__(pyTest left, pyTest other): 1085 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) 1086 | * cdef pyTest tt = pyTest(t.test1) # <<<<<<<<<<<<<< 1087 | * return tt 1088 | * 1089 | */ 1090 | __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_t.test1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) 1091 | __Pyx_GOTREF(__pyx_t_1); 1092 | __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error) 1093 | __Pyx_GOTREF(__pyx_t_2); 1094 | __Pyx_GIVEREF(__pyx_t_1); 1095 | PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); 1096 | __pyx_t_1 = 0; 1097 | __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4test_pyTest), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) 1098 | __Pyx_GOTREF(__pyx_t_1); 1099 | __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; 1100 | __pyx_v_tt = ((struct __pyx_obj_4test_pyTest *)__pyx_t_1); 1101 | __pyx_t_1 = 0; 1102 | 1103 | /* "CythonExample.pyx":24 1104 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) 1105 | * cdef pyTest tt = pyTest(t.test1) 1106 | * return tt # <<<<<<<<<<<<<< 1107 | * 1108 | * def __repr__(self): 1109 | */ 1110 | __Pyx_XDECREF(__pyx_r); 1111 | __Pyx_INCREF(((PyObject *)__pyx_v_tt)); 1112 | __pyx_r = ((PyObject *)__pyx_v_tt); 1113 | goto __pyx_L0; 1114 | 1115 | /* "CythonExample.pyx":21 1116 | * cdef pyTest tt = pyTest(t.test1) 1117 | * return tt 1118 | * def __sub__(pyTest left, pyTest other): # <<<<<<<<<<<<<< 1119 | * cdef Test t = left.thisptr.sub(other.thisptr[0]) 1120 | * cdef pyTest tt = pyTest(t.test1) 1121 | */ 1122 | 1123 | /* function exit code */ 1124 | __pyx_L1_error:; 1125 | __Pyx_XDECREF(__pyx_t_1); 1126 | __Pyx_XDECREF(__pyx_t_2); 1127 | __Pyx_AddTraceback("test.pyTest.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename); 1128 | __pyx_r = NULL; 1129 | __pyx_L0:; 1130 | __Pyx_XDECREF((PyObject *)__pyx_v_tt); 1131 | __Pyx_XGIVEREF(__pyx_r); 1132 | __Pyx_RefNannyFinishContext(); 1133 | return __pyx_r; 1134 | } 1135 | 1136 | /* "CythonExample.pyx":26 1137 | * return tt 1138 | * 1139 | * def __repr__(self): # <<<<<<<<<<<<<< 1140 | * return "pyTest[%s]" % (self.thisptr.test1) 1141 | * 1142 | */ 1143 | 1144 | /* Python wrapper */ 1145 | static PyObject *__pyx_pw_4test_6pyTest_9__repr__(PyObject *__pyx_v_self); /*proto*/ 1146 | static PyObject *__pyx_pw_4test_6pyTest_9__repr__(PyObject *__pyx_v_self) { 1147 | PyObject *__pyx_r = 0; 1148 | __Pyx_RefNannyDeclarations 1149 | __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); 1150 | __pyx_r = __pyx_pf_4test_6pyTest_8__repr__(((struct __pyx_obj_4test_pyTest *)__pyx_v_self)); 1151 | 1152 | /* function exit code */ 1153 | __Pyx_RefNannyFinishContext(); 1154 | return __pyx_r; 1155 | } 1156 | 1157 | static PyObject *__pyx_pf_4test_6pyTest_8__repr__(struct __pyx_obj_4test_pyTest *__pyx_v_self) { 1158 | PyObject *__pyx_r = NULL; 1159 | __Pyx_RefNannyDeclarations 1160 | PyObject *__pyx_t_1 = NULL; 1161 | PyObject *__pyx_t_2 = NULL; 1162 | __Pyx_RefNannySetupContext("__repr__", 0); 1163 | 1164 | /* "CythonExample.pyx":27 1165 | * 1166 | * def __repr__(self): 1167 | * return "pyTest[%s]" % (self.thisptr.test1) # <<<<<<<<<<<<<< 1168 | * 1169 | * def returnFive(self): 1170 | */ 1171 | __Pyx_XDECREF(__pyx_r); 1172 | __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->test1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) 1173 | __Pyx_GOTREF(__pyx_t_1); 1174 | __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_pyTest_s, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) 1175 | __Pyx_GOTREF(__pyx_t_2); 1176 | __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; 1177 | __pyx_r = __pyx_t_2; 1178 | __pyx_t_2 = 0; 1179 | goto __pyx_L0; 1180 | 1181 | /* "CythonExample.pyx":26 1182 | * return tt 1183 | * 1184 | * def __repr__(self): # <<<<<<<<<<<<<< 1185 | * return "pyTest[%s]" % (self.thisptr.test1) 1186 | * 1187 | */ 1188 | 1189 | /* function exit code */ 1190 | __pyx_L1_error:; 1191 | __Pyx_XDECREF(__pyx_t_1); 1192 | __Pyx_XDECREF(__pyx_t_2); 1193 | __Pyx_AddTraceback("test.pyTest.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); 1194 | __pyx_r = NULL; 1195 | __pyx_L0:; 1196 | __Pyx_XGIVEREF(__pyx_r); 1197 | __Pyx_RefNannyFinishContext(); 1198 | return __pyx_r; 1199 | } 1200 | 1201 | /* "CythonExample.pyx":29 1202 | * return "pyTest[%s]" % (self.thisptr.test1) 1203 | * 1204 | * def returnFive(self): # <<<<<<<<<<<<<< 1205 | * return self.thisptr.returnFive() 1206 | * 1207 | */ 1208 | 1209 | /* Python wrapper */ 1210 | static PyObject *__pyx_pw_4test_6pyTest_11returnFive(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ 1211 | static PyObject *__pyx_pw_4test_6pyTest_11returnFive(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { 1212 | PyObject *__pyx_r = 0; 1213 | __Pyx_RefNannyDeclarations 1214 | __Pyx_RefNannySetupContext("returnFive (wrapper)", 0); 1215 | __pyx_r = __pyx_pf_4test_6pyTest_10returnFive(((struct __pyx_obj_4test_pyTest *)__pyx_v_self)); 1216 | 1217 | /* function exit code */ 1218 | __Pyx_RefNannyFinishContext(); 1219 | return __pyx_r; 1220 | } 1221 | 1222 | static PyObject *__pyx_pf_4test_6pyTest_10returnFive(struct __pyx_obj_4test_pyTest *__pyx_v_self) { 1223 | PyObject *__pyx_r = NULL; 1224 | __Pyx_RefNannyDeclarations 1225 | PyObject *__pyx_t_1 = NULL; 1226 | __Pyx_RefNannySetupContext("returnFive", 0); 1227 | 1228 | /* "CythonExample.pyx":30 1229 | * 1230 | * def returnFive(self): 1231 | * return self.thisptr.returnFive() # <<<<<<<<<<<<<< 1232 | * 1233 | * def printMe(self): 1234 | */ 1235 | __Pyx_XDECREF(__pyx_r); 1236 | __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->returnFive()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) 1237 | __Pyx_GOTREF(__pyx_t_1); 1238 | __pyx_r = __pyx_t_1; 1239 | __pyx_t_1 = 0; 1240 | goto __pyx_L0; 1241 | 1242 | /* "CythonExample.pyx":29 1243 | * return "pyTest[%s]" % (self.thisptr.test1) 1244 | * 1245 | * def returnFive(self): # <<<<<<<<<<<<<< 1246 | * return self.thisptr.returnFive() 1247 | * 1248 | */ 1249 | 1250 | /* function exit code */ 1251 | __pyx_L1_error:; 1252 | __Pyx_XDECREF(__pyx_t_1); 1253 | __Pyx_AddTraceback("test.pyTest.returnFive", __pyx_clineno, __pyx_lineno, __pyx_filename); 1254 | __pyx_r = NULL; 1255 | __pyx_L0:; 1256 | __Pyx_XGIVEREF(__pyx_r); 1257 | __Pyx_RefNannyFinishContext(); 1258 | return __pyx_r; 1259 | } 1260 | 1261 | /* "CythonExample.pyx":32 1262 | * return self.thisptr.returnFive() 1263 | * 1264 | * def printMe(self): # <<<<<<<<<<<<<< 1265 | * return "hello world" 1266 | */ 1267 | 1268 | /* Python wrapper */ 1269 | static PyObject *__pyx_pw_4test_6pyTest_13printMe(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ 1270 | static PyObject *__pyx_pw_4test_6pyTest_13printMe(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { 1271 | PyObject *__pyx_r = 0; 1272 | __Pyx_RefNannyDeclarations 1273 | __Pyx_RefNannySetupContext("printMe (wrapper)", 0); 1274 | __pyx_r = __pyx_pf_4test_6pyTest_12printMe(((struct __pyx_obj_4test_pyTest *)__pyx_v_self)); 1275 | 1276 | /* function exit code */ 1277 | __Pyx_RefNannyFinishContext(); 1278 | return __pyx_r; 1279 | } 1280 | 1281 | static PyObject *__pyx_pf_4test_6pyTest_12printMe(CYTHON_UNUSED struct __pyx_obj_4test_pyTest *__pyx_v_self) { 1282 | PyObject *__pyx_r = NULL; 1283 | __Pyx_RefNannyDeclarations 1284 | __Pyx_RefNannySetupContext("printMe", 0); 1285 | 1286 | /* "CythonExample.pyx":33 1287 | * 1288 | * def printMe(self): 1289 | * return "hello world" # <<<<<<<<<<<<<< 1290 | */ 1291 | __Pyx_XDECREF(__pyx_r); 1292 | __Pyx_INCREF(__pyx_kp_s_hello_world); 1293 | __pyx_r = __pyx_kp_s_hello_world; 1294 | goto __pyx_L0; 1295 | 1296 | /* "CythonExample.pyx":32 1297 | * return self.thisptr.returnFive() 1298 | * 1299 | * def printMe(self): # <<<<<<<<<<<<<< 1300 | * return "hello world" 1301 | */ 1302 | 1303 | /* function exit code */ 1304 | __pyx_L0:; 1305 | __Pyx_XGIVEREF(__pyx_r); 1306 | __Pyx_RefNannyFinishContext(); 1307 | return __pyx_r; 1308 | } 1309 | 1310 | static PyObject *__pyx_tp_new_4test_pyTest(PyTypeObject *t, PyObject *a, PyObject *k) { 1311 | PyObject *o; 1312 | if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { 1313 | o = (*t->tp_alloc)(t, 0); 1314 | } else { 1315 | o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); 1316 | } 1317 | if (unlikely(!o)) return 0; 1318 | if (unlikely(__pyx_pw_4test_6pyTest_1__cinit__(o, a, k) < 0)) goto bad; 1319 | return o; 1320 | bad: 1321 | Py_DECREF(o); o = 0; 1322 | return NULL; 1323 | } 1324 | 1325 | static void __pyx_tp_dealloc_4test_pyTest(PyObject *o) { 1326 | #if PY_VERSION_HEX >= 0x030400a1 1327 | if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { 1328 | if (PyObject_CallFinalizerFromDealloc(o)) return; 1329 | } 1330 | #endif 1331 | { 1332 | PyObject *etype, *eval, *etb; 1333 | PyErr_Fetch(&etype, &eval, &etb); 1334 | ++Py_REFCNT(o); 1335 | __pyx_pw_4test_6pyTest_3__dealloc__(o); 1336 | --Py_REFCNT(o); 1337 | PyErr_Restore(etype, eval, etb); 1338 | } 1339 | (*Py_TYPE(o)->tp_free)(o); 1340 | } 1341 | 1342 | static PyMethodDef __pyx_methods_4test_pyTest[] = { 1343 | {"returnFive", (PyCFunction)__pyx_pw_4test_6pyTest_11returnFive, METH_NOARGS, 0}, 1344 | {"printMe", (PyCFunction)__pyx_pw_4test_6pyTest_13printMe, METH_NOARGS, 0}, 1345 | {0, 0, 0, 0} 1346 | }; 1347 | 1348 | static PyNumberMethods __pyx_tp_as_number_pyTest = { 1349 | __pyx_pw_4test_6pyTest_5__add__, /*nb_add*/ 1350 | __pyx_pw_4test_6pyTest_7__sub__, /*nb_subtract*/ 1351 | 0, /*nb_multiply*/ 1352 | #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY 1353 | 0, /*nb_divide*/ 1354 | #endif 1355 | 0, /*nb_remainder*/ 1356 | 0, /*nb_divmod*/ 1357 | 0, /*nb_power*/ 1358 | 0, /*nb_negative*/ 1359 | 0, /*nb_positive*/ 1360 | 0, /*nb_absolute*/ 1361 | 0, /*nb_nonzero*/ 1362 | 0, /*nb_invert*/ 1363 | 0, /*nb_lshift*/ 1364 | 0, /*nb_rshift*/ 1365 | 0, /*nb_and*/ 1366 | 0, /*nb_xor*/ 1367 | 0, /*nb_or*/ 1368 | #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY 1369 | 0, /*nb_coerce*/ 1370 | #endif 1371 | 0, /*nb_int*/ 1372 | #if PY_MAJOR_VERSION < 3 1373 | 0, /*nb_long*/ 1374 | #else 1375 | 0, /*reserved*/ 1376 | #endif 1377 | 0, /*nb_float*/ 1378 | #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY 1379 | 0, /*nb_oct*/ 1380 | #endif 1381 | #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY 1382 | 0, /*nb_hex*/ 1383 | #endif 1384 | 0, /*nb_inplace_add*/ 1385 | 0, /*nb_inplace_subtract*/ 1386 | 0, /*nb_inplace_multiply*/ 1387 | #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY 1388 | 0, /*nb_inplace_divide*/ 1389 | #endif 1390 | 0, /*nb_inplace_remainder*/ 1391 | 0, /*nb_inplace_power*/ 1392 | 0, /*nb_inplace_lshift*/ 1393 | 0, /*nb_inplace_rshift*/ 1394 | 0, /*nb_inplace_and*/ 1395 | 0, /*nb_inplace_xor*/ 1396 | 0, /*nb_inplace_or*/ 1397 | 0, /*nb_floor_divide*/ 1398 | 0, /*nb_true_divide*/ 1399 | 0, /*nb_inplace_floor_divide*/ 1400 | 0, /*nb_inplace_true_divide*/ 1401 | 0, /*nb_index*/ 1402 | #if PY_VERSION_HEX >= 0x03050000 1403 | 0, /*nb_matrix_multiply*/ 1404 | #endif 1405 | #if PY_VERSION_HEX >= 0x03050000 1406 | 0, /*nb_inplace_matrix_multiply*/ 1407 | #endif 1408 | }; 1409 | 1410 | static PyTypeObject __pyx_type_4test_pyTest = { 1411 | PyVarObject_HEAD_INIT(0, 0) 1412 | "test.pyTest", /*tp_name*/ 1413 | sizeof(struct __pyx_obj_4test_pyTest), /*tp_basicsize*/ 1414 | 0, /*tp_itemsize*/ 1415 | __pyx_tp_dealloc_4test_pyTest, /*tp_dealloc*/ 1416 | 0, /*tp_print*/ 1417 | 0, /*tp_getattr*/ 1418 | 0, /*tp_setattr*/ 1419 | #if PY_MAJOR_VERSION < 3 1420 | 0, /*tp_compare*/ 1421 | #endif 1422 | #if PY_MAJOR_VERSION >= 3 1423 | 0, /*tp_as_async*/ 1424 | #endif 1425 | __pyx_pw_4test_6pyTest_9__repr__, /*tp_repr*/ 1426 | &__pyx_tp_as_number_pyTest, /*tp_as_number*/ 1427 | 0, /*tp_as_sequence*/ 1428 | 0, /*tp_as_mapping*/ 1429 | 0, /*tp_hash*/ 1430 | 0, /*tp_call*/ 1431 | 0, /*tp_str*/ 1432 | 0, /*tp_getattro*/ 1433 | 0, /*tp_setattro*/ 1434 | 0, /*tp_as_buffer*/ 1435 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 1436 | 0, /*tp_doc*/ 1437 | 0, /*tp_traverse*/ 1438 | 0, /*tp_clear*/ 1439 | 0, /*tp_richcompare*/ 1440 | 0, /*tp_weaklistoffset*/ 1441 | 0, /*tp_iter*/ 1442 | 0, /*tp_iternext*/ 1443 | __pyx_methods_4test_pyTest, /*tp_methods*/ 1444 | 0, /*tp_members*/ 1445 | 0, /*tp_getset*/ 1446 | 0, /*tp_base*/ 1447 | 0, /*tp_dict*/ 1448 | 0, /*tp_descr_get*/ 1449 | 0, /*tp_descr_set*/ 1450 | 0, /*tp_dictoffset*/ 1451 | 0, /*tp_init*/ 1452 | 0, /*tp_alloc*/ 1453 | __pyx_tp_new_4test_pyTest, /*tp_new*/ 1454 | 0, /*tp_free*/ 1455 | 0, /*tp_is_gc*/ 1456 | 0, /*tp_bases*/ 1457 | 0, /*tp_mro*/ 1458 | 0, /*tp_cache*/ 1459 | 0, /*tp_subclasses*/ 1460 | 0, /*tp_weaklist*/ 1461 | 0, /*tp_del*/ 1462 | 0, /*tp_version_tag*/ 1463 | #if PY_VERSION_HEX >= 0x030400a1 1464 | 0, /*tp_finalize*/ 1465 | #endif 1466 | }; 1467 | 1468 | static PyMethodDef __pyx_methods[] = { 1469 | {0, 0, 0, 0} 1470 | }; 1471 | 1472 | #if PY_MAJOR_VERSION >= 3 1473 | static struct PyModuleDef __pyx_moduledef = { 1474 | #if PY_VERSION_HEX < 0x03020000 1475 | { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, 1476 | #else 1477 | PyModuleDef_HEAD_INIT, 1478 | #endif 1479 | "test", 1480 | 0, /* m_doc */ 1481 | -1, /* m_size */ 1482 | __pyx_methods /* m_methods */, 1483 | NULL, /* m_reload */ 1484 | NULL, /* m_traverse */ 1485 | NULL, /* m_clear */ 1486 | NULL /* m_free */ 1487 | }; 1488 | #endif 1489 | 1490 | static __Pyx_StringTabEntry __pyx_string_tab[] = { 1491 | {&__pyx_kp_s_hello_world, __pyx_k_hello_world, sizeof(__pyx_k_hello_world), 0, 0, 1, 0}, 1492 | {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, 1493 | {&__pyx_kp_s_pyTest_s, __pyx_k_pyTest_s, sizeof(__pyx_k_pyTest_s), 0, 0, 1, 0}, 1494 | {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, 1495 | {&__pyx_n_s_test1, __pyx_k_test1, sizeof(__pyx_k_test1), 0, 0, 1, 1}, 1496 | {0, 0, 0, 0, 0, 0, 0} 1497 | }; 1498 | static int __Pyx_InitCachedBuiltins(void) { 1499 | return 0; 1500 | } 1501 | 1502 | static int __Pyx_InitCachedConstants(void) { 1503 | __Pyx_RefNannyDeclarations 1504 | __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); 1505 | __Pyx_RefNannyFinishContext(); 1506 | return 0; 1507 | } 1508 | 1509 | static int __Pyx_InitGlobals(void) { 1510 | if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); 1511 | return 0; 1512 | __pyx_L1_error:; 1513 | return -1; 1514 | } 1515 | 1516 | #if PY_MAJOR_VERSION < 3 1517 | PyMODINIT_FUNC inittest(void); /*proto*/ 1518 | PyMODINIT_FUNC inittest(void) 1519 | #else 1520 | PyMODINIT_FUNC PyInit_test(void); /*proto*/ 1521 | PyMODINIT_FUNC PyInit_test(void) 1522 | #endif 1523 | { 1524 | PyObject *__pyx_t_1 = NULL; 1525 | __Pyx_RefNannyDeclarations 1526 | #if CYTHON_REFNANNY 1527 | __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); 1528 | if (!__Pyx_RefNanny) { 1529 | PyErr_Clear(); 1530 | __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); 1531 | if (!__Pyx_RefNanny) 1532 | Py_FatalError("failed to import 'refnanny' module"); 1533 | } 1534 | #endif 1535 | __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_test(void)", 0); 1536 | if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1537 | __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) 1538 | __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) 1539 | __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) 1540 | #ifdef __Pyx_CyFunction_USED 1541 | if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1542 | #endif 1543 | #ifdef __Pyx_FusedFunction_USED 1544 | if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1545 | #endif 1546 | #ifdef __Pyx_Coroutine_USED 1547 | if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1548 | #endif 1549 | #ifdef __Pyx_Generator_USED 1550 | if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1551 | #endif 1552 | #ifdef __Pyx_StopAsyncIteration_USED 1553 | if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1554 | #endif 1555 | /*--- Library function declarations ---*/ 1556 | /*--- Threads initialization code ---*/ 1557 | #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS 1558 | #ifdef WITH_THREAD /* Python build with threading support? */ 1559 | PyEval_InitThreads(); 1560 | #endif 1561 | #endif 1562 | /*--- Module creation code ---*/ 1563 | #if PY_MAJOR_VERSION < 3 1564 | __pyx_m = Py_InitModule4("test", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); 1565 | #else 1566 | __pyx_m = PyModule_Create(&__pyx_moduledef); 1567 | #endif 1568 | if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) 1569 | __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) 1570 | Py_INCREF(__pyx_d); 1571 | __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) 1572 | #if CYTHON_COMPILING_IN_PYPY 1573 | Py_INCREF(__pyx_b); 1574 | #endif 1575 | if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); 1576 | /*--- Initialize various global constants etc. ---*/ 1577 | if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1578 | #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) 1579 | if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1580 | #endif 1581 | if (__pyx_module_is_main_test) { 1582 | if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1583 | } 1584 | #if PY_MAJOR_VERSION >= 3 1585 | { 1586 | PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) 1587 | if (!PyDict_GetItemString(modules, "test")) { 1588 | if (unlikely(PyDict_SetItemString(modules, "test", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) 1589 | } 1590 | } 1591 | #endif 1592 | /*--- Builtin init code ---*/ 1593 | if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1594 | /*--- Constants init code ---*/ 1595 | if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1596 | /*--- Global init code ---*/ 1597 | /*--- Variable export code ---*/ 1598 | /*--- Function export code ---*/ 1599 | /*--- Type init code ---*/ 1600 | if (PyType_Ready(&__pyx_type_4test_pyTest) < 0) __PYX_ERR(0, 10, __pyx_L1_error) 1601 | __pyx_type_4test_pyTest.tp_print = 0; 1602 | if (PyObject_SetAttrString(__pyx_m, "pyTest", (PyObject *)&__pyx_type_4test_pyTest) < 0) __PYX_ERR(0, 10, __pyx_L1_error) 1603 | __pyx_ptype_4test_pyTest = &__pyx_type_4test_pyTest; 1604 | /*--- Type import code ---*/ 1605 | /*--- Variable import code ---*/ 1606 | /*--- Function import code ---*/ 1607 | /*--- Execution code ---*/ 1608 | #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) 1609 | if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1610 | #endif 1611 | 1612 | /* "CythonExample.pyx":1 1613 | * cdef extern from "cpp_test.h": # <<<<<<<<<<<<<< 1614 | * cdef cppclass Test: 1615 | * Test() 1616 | */ 1617 | __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) 1618 | __Pyx_GOTREF(__pyx_t_1); 1619 | if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) 1620 | __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; 1621 | 1622 | /*--- Wrapped vars code ---*/ 1623 | 1624 | goto __pyx_L0; 1625 | __pyx_L1_error:; 1626 | __Pyx_XDECREF(__pyx_t_1); 1627 | if (__pyx_m) { 1628 | if (__pyx_d) { 1629 | __Pyx_AddTraceback("init test", __pyx_clineno, __pyx_lineno, __pyx_filename); 1630 | } 1631 | Py_DECREF(__pyx_m); __pyx_m = 0; 1632 | } else if (!PyErr_Occurred()) { 1633 | PyErr_SetString(PyExc_ImportError, "init test"); 1634 | } 1635 | __pyx_L0:; 1636 | __Pyx_RefNannyFinishContext(); 1637 | #if PY_MAJOR_VERSION < 3 1638 | return; 1639 | #else 1640 | return __pyx_m; 1641 | #endif 1642 | } 1643 | 1644 | /* --- Runtime support code --- */ 1645 | /* Refnanny */ 1646 | #if CYTHON_REFNANNY 1647 | static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { 1648 | PyObject *m = NULL, *p = NULL; 1649 | void *r = NULL; 1650 | m = PyImport_ImportModule((char *)modname); 1651 | if (!m) goto end; 1652 | p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); 1653 | if (!p) goto end; 1654 | r = PyLong_AsVoidPtr(p); 1655 | end: 1656 | Py_XDECREF(p); 1657 | Py_XDECREF(m); 1658 | return (__Pyx_RefNannyAPIStruct *)r; 1659 | } 1660 | #endif 1661 | 1662 | /* RaiseDoubleKeywords */ 1663 | static void __Pyx_RaiseDoubleKeywordsError( 1664 | const char* func_name, 1665 | PyObject* kw_name) 1666 | { 1667 | PyErr_Format(PyExc_TypeError, 1668 | #if PY_MAJOR_VERSION >= 3 1669 | "%s() got multiple values for keyword argument '%U'", func_name, kw_name); 1670 | #else 1671 | "%s() got multiple values for keyword argument '%s'", func_name, 1672 | PyString_AsString(kw_name)); 1673 | #endif 1674 | } 1675 | 1676 | /* ParseKeywords */ 1677 | static int __Pyx_ParseOptionalKeywords( 1678 | PyObject *kwds, 1679 | PyObject **argnames[], 1680 | PyObject *kwds2, 1681 | PyObject *values[], 1682 | Py_ssize_t num_pos_args, 1683 | const char* function_name) 1684 | { 1685 | PyObject *key = 0, *value = 0; 1686 | Py_ssize_t pos = 0; 1687 | PyObject*** name; 1688 | PyObject*** first_kw_arg = argnames + num_pos_args; 1689 | while (PyDict_Next(kwds, &pos, &key, &value)) { 1690 | name = first_kw_arg; 1691 | while (*name && (**name != key)) name++; 1692 | if (*name) { 1693 | values[name-argnames] = value; 1694 | continue; 1695 | } 1696 | name = first_kw_arg; 1697 | #if PY_MAJOR_VERSION < 3 1698 | if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { 1699 | while (*name) { 1700 | if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) 1701 | && _PyString_Eq(**name, key)) { 1702 | values[name-argnames] = value; 1703 | break; 1704 | } 1705 | name++; 1706 | } 1707 | if (*name) continue; 1708 | else { 1709 | PyObject*** argname = argnames; 1710 | while (argname != first_kw_arg) { 1711 | if ((**argname == key) || ( 1712 | (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) 1713 | && _PyString_Eq(**argname, key))) { 1714 | goto arg_passed_twice; 1715 | } 1716 | argname++; 1717 | } 1718 | } 1719 | } else 1720 | #endif 1721 | if (likely(PyUnicode_Check(key))) { 1722 | while (*name) { 1723 | int cmp = (**name == key) ? 0 : 1724 | #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 1725 | (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : 1726 | #endif 1727 | PyUnicode_Compare(**name, key); 1728 | if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; 1729 | if (cmp == 0) { 1730 | values[name-argnames] = value; 1731 | break; 1732 | } 1733 | name++; 1734 | } 1735 | if (*name) continue; 1736 | else { 1737 | PyObject*** argname = argnames; 1738 | while (argname != first_kw_arg) { 1739 | int cmp = (**argname == key) ? 0 : 1740 | #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 1741 | (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : 1742 | #endif 1743 | PyUnicode_Compare(**argname, key); 1744 | if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; 1745 | if (cmp == 0) goto arg_passed_twice; 1746 | argname++; 1747 | } 1748 | } 1749 | } else 1750 | goto invalid_keyword_type; 1751 | if (kwds2) { 1752 | if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; 1753 | } else { 1754 | goto invalid_keyword; 1755 | } 1756 | } 1757 | return 0; 1758 | arg_passed_twice: 1759 | __Pyx_RaiseDoubleKeywordsError(function_name, key); 1760 | goto bad; 1761 | invalid_keyword_type: 1762 | PyErr_Format(PyExc_TypeError, 1763 | "%.200s() keywords must be strings", function_name); 1764 | goto bad; 1765 | invalid_keyword: 1766 | PyErr_Format(PyExc_TypeError, 1767 | #if PY_MAJOR_VERSION < 3 1768 | "%.200s() got an unexpected keyword argument '%.200s'", 1769 | function_name, PyString_AsString(key)); 1770 | #else 1771 | "%s() got an unexpected keyword argument '%U'", 1772 | function_name, key); 1773 | #endif 1774 | bad: 1775 | return -1; 1776 | } 1777 | 1778 | /* RaiseArgTupleInvalid */ 1779 | static void __Pyx_RaiseArgtupleInvalid( 1780 | const char* func_name, 1781 | int exact, 1782 | Py_ssize_t num_min, 1783 | Py_ssize_t num_max, 1784 | Py_ssize_t num_found) 1785 | { 1786 | Py_ssize_t num_expected; 1787 | const char *more_or_less; 1788 | if (num_found < num_min) { 1789 | num_expected = num_min; 1790 | more_or_less = "at least"; 1791 | } else { 1792 | num_expected = num_max; 1793 | more_or_less = "at most"; 1794 | } 1795 | if (exact) { 1796 | more_or_less = "exactly"; 1797 | } 1798 | PyErr_Format(PyExc_TypeError, 1799 | "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", 1800 | func_name, more_or_less, num_expected, 1801 | (num_expected == 1) ? "" : "s", num_found); 1802 | } 1803 | 1804 | /* ArgTypeTest */ 1805 | static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { 1806 | PyErr_Format(PyExc_TypeError, 1807 | "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", 1808 | name, type->tp_name, Py_TYPE(obj)->tp_name); 1809 | } 1810 | static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, 1811 | const char *name, int exact) 1812 | { 1813 | if (unlikely(!type)) { 1814 | PyErr_SetString(PyExc_SystemError, "Missing type object"); 1815 | return 0; 1816 | } 1817 | if (none_allowed && obj == Py_None) return 1; 1818 | else if (exact) { 1819 | if (likely(Py_TYPE(obj) == type)) return 1; 1820 | #if PY_MAJOR_VERSION == 2 1821 | else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; 1822 | #endif 1823 | } 1824 | else { 1825 | if (likely(PyObject_TypeCheck(obj, type))) return 1; 1826 | } 1827 | __Pyx_RaiseArgumentTypeInvalid(name, obj, type); 1828 | return 0; 1829 | } 1830 | 1831 | /* PyObjectCall */ 1832 | #if CYTHON_COMPILING_IN_CPYTHON 1833 | static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { 1834 | PyObject *result; 1835 | ternaryfunc call = func->ob_type->tp_call; 1836 | if (unlikely(!call)) 1837 | return PyObject_Call(func, arg, kw); 1838 | if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) 1839 | return NULL; 1840 | result = (*call)(func, arg, kw); 1841 | Py_LeaveRecursiveCall(); 1842 | if (unlikely(!result) && unlikely(!PyErr_Occurred())) { 1843 | PyErr_SetString( 1844 | PyExc_SystemError, 1845 | "NULL result without error in PyObject_Call"); 1846 | } 1847 | return result; 1848 | } 1849 | #endif 1850 | 1851 | /* CodeObjectCache */ 1852 | static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { 1853 | int start = 0, mid = 0, end = count - 1; 1854 | if (end >= 0 && code_line > entries[end].code_line) { 1855 | return count; 1856 | } 1857 | while (start < end) { 1858 | mid = start + (end - start) / 2; 1859 | if (code_line < entries[mid].code_line) { 1860 | end = mid; 1861 | } else if (code_line > entries[mid].code_line) { 1862 | start = mid + 1; 1863 | } else { 1864 | return mid; 1865 | } 1866 | } 1867 | if (code_line <= entries[mid].code_line) { 1868 | return mid; 1869 | } else { 1870 | return mid + 1; 1871 | } 1872 | } 1873 | static PyCodeObject *__pyx_find_code_object(int code_line) { 1874 | PyCodeObject* code_object; 1875 | int pos; 1876 | if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { 1877 | return NULL; 1878 | } 1879 | pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); 1880 | if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { 1881 | return NULL; 1882 | } 1883 | code_object = __pyx_code_cache.entries[pos].code_object; 1884 | Py_INCREF(code_object); 1885 | return code_object; 1886 | } 1887 | static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { 1888 | int pos, i; 1889 | __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; 1890 | if (unlikely(!code_line)) { 1891 | return; 1892 | } 1893 | if (unlikely(!entries)) { 1894 | entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); 1895 | if (likely(entries)) { 1896 | __pyx_code_cache.entries = entries; 1897 | __pyx_code_cache.max_count = 64; 1898 | __pyx_code_cache.count = 1; 1899 | entries[0].code_line = code_line; 1900 | entries[0].code_object = code_object; 1901 | Py_INCREF(code_object); 1902 | } 1903 | return; 1904 | } 1905 | pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); 1906 | if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { 1907 | PyCodeObject* tmp = entries[pos].code_object; 1908 | entries[pos].code_object = code_object; 1909 | Py_DECREF(tmp); 1910 | return; 1911 | } 1912 | if (__pyx_code_cache.count == __pyx_code_cache.max_count) { 1913 | int new_max = __pyx_code_cache.max_count + 64; 1914 | entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( 1915 | __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); 1916 | if (unlikely(!entries)) { 1917 | return; 1918 | } 1919 | __pyx_code_cache.entries = entries; 1920 | __pyx_code_cache.max_count = new_max; 1921 | } 1922 | for (i=__pyx_code_cache.count; i>pos; i--) { 1923 | entries[i] = entries[i-1]; 1924 | } 1925 | entries[pos].code_line = code_line; 1926 | entries[pos].code_object = code_object; 1927 | __pyx_code_cache.count++; 1928 | Py_INCREF(code_object); 1929 | } 1930 | 1931 | /* AddTraceback */ 1932 | #include "compile.h" 1933 | #include "frameobject.h" 1934 | #include "traceback.h" 1935 | static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( 1936 | const char *funcname, int c_line, 1937 | int py_line, const char *filename) { 1938 | PyCodeObject *py_code = 0; 1939 | PyObject *py_srcfile = 0; 1940 | PyObject *py_funcname = 0; 1941 | #if PY_MAJOR_VERSION < 3 1942 | py_srcfile = PyString_FromString(filename); 1943 | #else 1944 | py_srcfile = PyUnicode_FromString(filename); 1945 | #endif 1946 | if (!py_srcfile) goto bad; 1947 | if (c_line) { 1948 | #if PY_MAJOR_VERSION < 3 1949 | py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); 1950 | #else 1951 | py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); 1952 | #endif 1953 | } 1954 | else { 1955 | #if PY_MAJOR_VERSION < 3 1956 | py_funcname = PyString_FromString(funcname); 1957 | #else 1958 | py_funcname = PyUnicode_FromString(funcname); 1959 | #endif 1960 | } 1961 | if (!py_funcname) goto bad; 1962 | py_code = __Pyx_PyCode_New( 1963 | 0, 1964 | 0, 1965 | 0, 1966 | 0, 1967 | 0, 1968 | __pyx_empty_bytes, /*PyObject *code,*/ 1969 | __pyx_empty_tuple, /*PyObject *consts,*/ 1970 | __pyx_empty_tuple, /*PyObject *names,*/ 1971 | __pyx_empty_tuple, /*PyObject *varnames,*/ 1972 | __pyx_empty_tuple, /*PyObject *freevars,*/ 1973 | __pyx_empty_tuple, /*PyObject *cellvars,*/ 1974 | py_srcfile, /*PyObject *filename,*/ 1975 | py_funcname, /*PyObject *name,*/ 1976 | py_line, 1977 | __pyx_empty_bytes /*PyObject *lnotab*/ 1978 | ); 1979 | Py_DECREF(py_srcfile); 1980 | Py_DECREF(py_funcname); 1981 | return py_code; 1982 | bad: 1983 | Py_XDECREF(py_srcfile); 1984 | Py_XDECREF(py_funcname); 1985 | return NULL; 1986 | } 1987 | static void __Pyx_AddTraceback(const char *funcname, int c_line, 1988 | int py_line, const char *filename) { 1989 | PyCodeObject *py_code = 0; 1990 | PyFrameObject *py_frame = 0; 1991 | py_code = __pyx_find_code_object(c_line ? c_line : py_line); 1992 | if (!py_code) { 1993 | py_code = __Pyx_CreateCodeObjectForTraceback( 1994 | funcname, c_line, py_line, filename); 1995 | if (!py_code) goto bad; 1996 | __pyx_insert_code_object(c_line ? c_line : py_line, py_code); 1997 | } 1998 | py_frame = PyFrame_New( 1999 | PyThreadState_GET(), /*PyThreadState *tstate,*/ 2000 | py_code, /*PyCodeObject *code,*/ 2001 | __pyx_d, /*PyObject *globals,*/ 2002 | 0 /*PyObject *locals*/ 2003 | ); 2004 | if (!py_frame) goto bad; 2005 | __Pyx_PyFrame_SetLineNumber(py_frame, py_line); 2006 | PyTraceBack_Here(py_frame); 2007 | bad: 2008 | Py_XDECREF(py_code); 2009 | Py_XDECREF(py_frame); 2010 | } 2011 | 2012 | /* CIntFromPyVerify */ 2013 | #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ 2014 | __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) 2015 | #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ 2016 | __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) 2017 | #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ 2018 | {\ 2019 | func_type value = func_value;\ 2020 | if (sizeof(target_type) < sizeof(func_type)) {\ 2021 | if (unlikely(value != (func_type) (target_type) value)) {\ 2022 | func_type zero = 0;\ 2023 | if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ 2024 | return (target_type) -1;\ 2025 | if (is_unsigned && unlikely(value < zero))\ 2026 | goto raise_neg_overflow;\ 2027 | else\ 2028 | goto raise_overflow;\ 2029 | }\ 2030 | }\ 2031 | return (target_type) value;\ 2032 | } 2033 | 2034 | /* CIntToPy */ 2035 | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { 2036 | const int neg_one = (int) -1, const_zero = (int) 0; 2037 | const int is_unsigned = neg_one > const_zero; 2038 | if (is_unsigned) { 2039 | if (sizeof(int) < sizeof(long)) { 2040 | return PyInt_FromLong((long) value); 2041 | } else if (sizeof(int) <= sizeof(unsigned long)) { 2042 | return PyLong_FromUnsignedLong((unsigned long) value); 2043 | #ifdef HAVE_LONG_LONG 2044 | } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { 2045 | return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); 2046 | #endif 2047 | } 2048 | } else { 2049 | if (sizeof(int) <= sizeof(long)) { 2050 | return PyInt_FromLong((long) value); 2051 | #ifdef HAVE_LONG_LONG 2052 | } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { 2053 | return PyLong_FromLongLong((PY_LONG_LONG) value); 2054 | #endif 2055 | } 2056 | } 2057 | { 2058 | int one = 1; int little = (int)*(unsigned char *)&one; 2059 | unsigned char *bytes = (unsigned char *)&value; 2060 | return _PyLong_FromByteArray(bytes, sizeof(int), 2061 | little, !is_unsigned); 2062 | } 2063 | } 2064 | 2065 | /* CIntFromPy */ 2066 | static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { 2067 | const int neg_one = (int) -1, const_zero = (int) 0; 2068 | const int is_unsigned = neg_one > const_zero; 2069 | #if PY_MAJOR_VERSION < 3 2070 | if (likely(PyInt_Check(x))) { 2071 | if (sizeof(int) < sizeof(long)) { 2072 | __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) 2073 | } else { 2074 | long val = PyInt_AS_LONG(x); 2075 | if (is_unsigned && unlikely(val < 0)) { 2076 | goto raise_neg_overflow; 2077 | } 2078 | return (int) val; 2079 | } 2080 | } else 2081 | #endif 2082 | if (likely(PyLong_Check(x))) { 2083 | if (is_unsigned) { 2084 | #if CYTHON_USE_PYLONG_INTERNALS 2085 | const digit* digits = ((PyLongObject*)x)->ob_digit; 2086 | switch (Py_SIZE(x)) { 2087 | case 0: return (int) 0; 2088 | case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) 2089 | case 2: 2090 | if (8 * sizeof(int) > 1 * PyLong_SHIFT) { 2091 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2092 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2093 | } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { 2094 | return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); 2095 | } 2096 | } 2097 | break; 2098 | case 3: 2099 | if (8 * sizeof(int) > 2 * PyLong_SHIFT) { 2100 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2101 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2102 | } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { 2103 | return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); 2104 | } 2105 | } 2106 | break; 2107 | case 4: 2108 | if (8 * sizeof(int) > 3 * PyLong_SHIFT) { 2109 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2110 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2111 | } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { 2112 | return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); 2113 | } 2114 | } 2115 | break; 2116 | } 2117 | #endif 2118 | #if CYTHON_COMPILING_IN_CPYTHON 2119 | if (unlikely(Py_SIZE(x) < 0)) { 2120 | goto raise_neg_overflow; 2121 | } 2122 | #else 2123 | { 2124 | int result = PyObject_RichCompareBool(x, Py_False, Py_LT); 2125 | if (unlikely(result < 0)) 2126 | return (int) -1; 2127 | if (unlikely(result == 1)) 2128 | goto raise_neg_overflow; 2129 | } 2130 | #endif 2131 | if (sizeof(int) <= sizeof(unsigned long)) { 2132 | __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) 2133 | #ifdef HAVE_LONG_LONG 2134 | } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { 2135 | __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) 2136 | #endif 2137 | } 2138 | } else { 2139 | #if CYTHON_USE_PYLONG_INTERNALS 2140 | const digit* digits = ((PyLongObject*)x)->ob_digit; 2141 | switch (Py_SIZE(x)) { 2142 | case 0: return (int) 0; 2143 | case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) 2144 | case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) 2145 | case -2: 2146 | if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { 2147 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2148 | __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2149 | } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { 2150 | return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2151 | } 2152 | } 2153 | break; 2154 | case 2: 2155 | if (8 * sizeof(int) > 1 * PyLong_SHIFT) { 2156 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2157 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2158 | } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { 2159 | return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2160 | } 2161 | } 2162 | break; 2163 | case -3: 2164 | if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { 2165 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2166 | __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2167 | } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { 2168 | return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2169 | } 2170 | } 2171 | break; 2172 | case 3: 2173 | if (8 * sizeof(int) > 2 * PyLong_SHIFT) { 2174 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2175 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2176 | } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { 2177 | return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2178 | } 2179 | } 2180 | break; 2181 | case -4: 2182 | if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { 2183 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2184 | __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2185 | } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { 2186 | return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2187 | } 2188 | } 2189 | break; 2190 | case 4: 2191 | if (8 * sizeof(int) > 3 * PyLong_SHIFT) { 2192 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2193 | __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2194 | } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { 2195 | return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); 2196 | } 2197 | } 2198 | break; 2199 | } 2200 | #endif 2201 | if (sizeof(int) <= sizeof(long)) { 2202 | __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) 2203 | #ifdef HAVE_LONG_LONG 2204 | } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { 2205 | __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) 2206 | #endif 2207 | } 2208 | } 2209 | { 2210 | #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) 2211 | PyErr_SetString(PyExc_RuntimeError, 2212 | "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); 2213 | #else 2214 | int val; 2215 | PyObject *v = __Pyx_PyNumber_IntOrLong(x); 2216 | #if PY_MAJOR_VERSION < 3 2217 | if (likely(v) && !PyLong_Check(v)) { 2218 | PyObject *tmp = v; 2219 | v = PyNumber_Long(tmp); 2220 | Py_DECREF(tmp); 2221 | } 2222 | #endif 2223 | if (likely(v)) { 2224 | int one = 1; int is_little = (int)*(unsigned char *)&one; 2225 | unsigned char *bytes = (unsigned char *)&val; 2226 | int ret = _PyLong_AsByteArray((PyLongObject *)v, 2227 | bytes, sizeof(val), 2228 | is_little, !is_unsigned); 2229 | Py_DECREF(v); 2230 | if (likely(!ret)) 2231 | return val; 2232 | } 2233 | #endif 2234 | return (int) -1; 2235 | } 2236 | } else { 2237 | int val; 2238 | PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); 2239 | if (!tmp) return (int) -1; 2240 | val = __Pyx_PyInt_As_int(tmp); 2241 | Py_DECREF(tmp); 2242 | return val; 2243 | } 2244 | raise_overflow: 2245 | PyErr_SetString(PyExc_OverflowError, 2246 | "value too large to convert to int"); 2247 | return (int) -1; 2248 | raise_neg_overflow: 2249 | PyErr_SetString(PyExc_OverflowError, 2250 | "can't convert negative value to int"); 2251 | return (int) -1; 2252 | } 2253 | 2254 | /* CIntToPy */ 2255 | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { 2256 | const long neg_one = (long) -1, const_zero = (long) 0; 2257 | const int is_unsigned = neg_one > const_zero; 2258 | if (is_unsigned) { 2259 | if (sizeof(long) < sizeof(long)) { 2260 | return PyInt_FromLong((long) value); 2261 | } else if (sizeof(long) <= sizeof(unsigned long)) { 2262 | return PyLong_FromUnsignedLong((unsigned long) value); 2263 | #ifdef HAVE_LONG_LONG 2264 | } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { 2265 | return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); 2266 | #endif 2267 | } 2268 | } else { 2269 | if (sizeof(long) <= sizeof(long)) { 2270 | return PyInt_FromLong((long) value); 2271 | #ifdef HAVE_LONG_LONG 2272 | } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { 2273 | return PyLong_FromLongLong((PY_LONG_LONG) value); 2274 | #endif 2275 | } 2276 | } 2277 | { 2278 | int one = 1; int little = (int)*(unsigned char *)&one; 2279 | unsigned char *bytes = (unsigned char *)&value; 2280 | return _PyLong_FromByteArray(bytes, sizeof(long), 2281 | little, !is_unsigned); 2282 | } 2283 | } 2284 | 2285 | /* CIntFromPy */ 2286 | static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { 2287 | const long neg_one = (long) -1, const_zero = (long) 0; 2288 | const int is_unsigned = neg_one > const_zero; 2289 | #if PY_MAJOR_VERSION < 3 2290 | if (likely(PyInt_Check(x))) { 2291 | if (sizeof(long) < sizeof(long)) { 2292 | __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) 2293 | } else { 2294 | long val = PyInt_AS_LONG(x); 2295 | if (is_unsigned && unlikely(val < 0)) { 2296 | goto raise_neg_overflow; 2297 | } 2298 | return (long) val; 2299 | } 2300 | } else 2301 | #endif 2302 | if (likely(PyLong_Check(x))) { 2303 | if (is_unsigned) { 2304 | #if CYTHON_USE_PYLONG_INTERNALS 2305 | const digit* digits = ((PyLongObject*)x)->ob_digit; 2306 | switch (Py_SIZE(x)) { 2307 | case 0: return (long) 0; 2308 | case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) 2309 | case 2: 2310 | if (8 * sizeof(long) > 1 * PyLong_SHIFT) { 2311 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2312 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2313 | } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { 2314 | return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); 2315 | } 2316 | } 2317 | break; 2318 | case 3: 2319 | if (8 * sizeof(long) > 2 * PyLong_SHIFT) { 2320 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2321 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2322 | } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { 2323 | return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); 2324 | } 2325 | } 2326 | break; 2327 | case 4: 2328 | if (8 * sizeof(long) > 3 * PyLong_SHIFT) { 2329 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2330 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2331 | } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { 2332 | return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); 2333 | } 2334 | } 2335 | break; 2336 | } 2337 | #endif 2338 | #if CYTHON_COMPILING_IN_CPYTHON 2339 | if (unlikely(Py_SIZE(x) < 0)) { 2340 | goto raise_neg_overflow; 2341 | } 2342 | #else 2343 | { 2344 | int result = PyObject_RichCompareBool(x, Py_False, Py_LT); 2345 | if (unlikely(result < 0)) 2346 | return (long) -1; 2347 | if (unlikely(result == 1)) 2348 | goto raise_neg_overflow; 2349 | } 2350 | #endif 2351 | if (sizeof(long) <= sizeof(unsigned long)) { 2352 | __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) 2353 | #ifdef HAVE_LONG_LONG 2354 | } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { 2355 | __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) 2356 | #endif 2357 | } 2358 | } else { 2359 | #if CYTHON_USE_PYLONG_INTERNALS 2360 | const digit* digits = ((PyLongObject*)x)->ob_digit; 2361 | switch (Py_SIZE(x)) { 2362 | case 0: return (long) 0; 2363 | case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) 2364 | case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) 2365 | case -2: 2366 | if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { 2367 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2368 | __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2369 | } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { 2370 | return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2371 | } 2372 | } 2373 | break; 2374 | case 2: 2375 | if (8 * sizeof(long) > 1 * PyLong_SHIFT) { 2376 | if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { 2377 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2378 | } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { 2379 | return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2380 | } 2381 | } 2382 | break; 2383 | case -3: 2384 | if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { 2385 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2386 | __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2387 | } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { 2388 | return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2389 | } 2390 | } 2391 | break; 2392 | case 3: 2393 | if (8 * sizeof(long) > 2 * PyLong_SHIFT) { 2394 | if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { 2395 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2396 | } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { 2397 | return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2398 | } 2399 | } 2400 | break; 2401 | case -4: 2402 | if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { 2403 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2404 | __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2405 | } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { 2406 | return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2407 | } 2408 | } 2409 | break; 2410 | case 4: 2411 | if (8 * sizeof(long) > 3 * PyLong_SHIFT) { 2412 | if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { 2413 | __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) 2414 | } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { 2415 | return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); 2416 | } 2417 | } 2418 | break; 2419 | } 2420 | #endif 2421 | if (sizeof(long) <= sizeof(long)) { 2422 | __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) 2423 | #ifdef HAVE_LONG_LONG 2424 | } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { 2425 | __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) 2426 | #endif 2427 | } 2428 | } 2429 | { 2430 | #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) 2431 | PyErr_SetString(PyExc_RuntimeError, 2432 | "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); 2433 | #else 2434 | long val; 2435 | PyObject *v = __Pyx_PyNumber_IntOrLong(x); 2436 | #if PY_MAJOR_VERSION < 3 2437 | if (likely(v) && !PyLong_Check(v)) { 2438 | PyObject *tmp = v; 2439 | v = PyNumber_Long(tmp); 2440 | Py_DECREF(tmp); 2441 | } 2442 | #endif 2443 | if (likely(v)) { 2444 | int one = 1; int is_little = (int)*(unsigned char *)&one; 2445 | unsigned char *bytes = (unsigned char *)&val; 2446 | int ret = _PyLong_AsByteArray((PyLongObject *)v, 2447 | bytes, sizeof(val), 2448 | is_little, !is_unsigned); 2449 | Py_DECREF(v); 2450 | if (likely(!ret)) 2451 | return val; 2452 | } 2453 | #endif 2454 | return (long) -1; 2455 | } 2456 | } else { 2457 | long val; 2458 | PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); 2459 | if (!tmp) return (long) -1; 2460 | val = __Pyx_PyInt_As_long(tmp); 2461 | Py_DECREF(tmp); 2462 | return val; 2463 | } 2464 | raise_overflow: 2465 | PyErr_SetString(PyExc_OverflowError, 2466 | "value too large to convert to long"); 2467 | return (long) -1; 2468 | raise_neg_overflow: 2469 | PyErr_SetString(PyExc_OverflowError, 2470 | "can't convert negative value to long"); 2471 | return (long) -1; 2472 | } 2473 | 2474 | /* CheckBinaryVersion */ 2475 | static int __Pyx_check_binary_version(void) { 2476 | char ctversion[4], rtversion[4]; 2477 | PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); 2478 | PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); 2479 | if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { 2480 | char message[200]; 2481 | PyOS_snprintf(message, sizeof(message), 2482 | "compiletime version %s of module '%.100s' " 2483 | "does not match runtime version %s", 2484 | ctversion, __Pyx_MODULE_NAME, rtversion); 2485 | return PyErr_WarnEx(NULL, message, 1); 2486 | } 2487 | return 0; 2488 | } 2489 | 2490 | /* InitStrings */ 2491 | static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { 2492 | while (t->p) { 2493 | #if PY_MAJOR_VERSION < 3 2494 | if (t->is_unicode) { 2495 | *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); 2496 | } else if (t->intern) { 2497 | *t->p = PyString_InternFromString(t->s); 2498 | } else { 2499 | *t->p = PyString_FromStringAndSize(t->s, t->n - 1); 2500 | } 2501 | #else 2502 | if (t->is_unicode | t->is_str) { 2503 | if (t->intern) { 2504 | *t->p = PyUnicode_InternFromString(t->s); 2505 | } else if (t->encoding) { 2506 | *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); 2507 | } else { 2508 | *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); 2509 | } 2510 | } else { 2511 | *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); 2512 | } 2513 | #endif 2514 | if (!*t->p) 2515 | return -1; 2516 | ++t; 2517 | } 2518 | return 0; 2519 | } 2520 | 2521 | static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { 2522 | return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); 2523 | } 2524 | static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { 2525 | Py_ssize_t ignore; 2526 | return __Pyx_PyObject_AsStringAndSize(o, &ignore); 2527 | } 2528 | static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { 2529 | #if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) 2530 | if ( 2531 | #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 2532 | __Pyx_sys_getdefaultencoding_not_ascii && 2533 | #endif 2534 | PyUnicode_Check(o)) { 2535 | #if PY_VERSION_HEX < 0x03030000 2536 | char* defenc_c; 2537 | PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); 2538 | if (!defenc) return NULL; 2539 | defenc_c = PyBytes_AS_STRING(defenc); 2540 | #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 2541 | { 2542 | char* end = defenc_c + PyBytes_GET_SIZE(defenc); 2543 | char* c; 2544 | for (c = defenc_c; c < end; c++) { 2545 | if ((unsigned char) (*c) >= 128) { 2546 | PyUnicode_AsASCIIString(o); 2547 | return NULL; 2548 | } 2549 | } 2550 | } 2551 | #endif 2552 | *length = PyBytes_GET_SIZE(defenc); 2553 | return defenc_c; 2554 | #else 2555 | if (__Pyx_PyUnicode_READY(o) == -1) return NULL; 2556 | #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 2557 | if (PyUnicode_IS_ASCII(o)) { 2558 | *length = PyUnicode_GET_LENGTH(o); 2559 | return PyUnicode_AsUTF8(o); 2560 | } else { 2561 | PyUnicode_AsASCIIString(o); 2562 | return NULL; 2563 | } 2564 | #else 2565 | return PyUnicode_AsUTF8AndSize(o, length); 2566 | #endif 2567 | #endif 2568 | } else 2569 | #endif 2570 | #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) 2571 | if (PyByteArray_Check(o)) { 2572 | *length = PyByteArray_GET_SIZE(o); 2573 | return PyByteArray_AS_STRING(o); 2574 | } else 2575 | #endif 2576 | { 2577 | char* result; 2578 | int r = PyBytes_AsStringAndSize(o, &result, length); 2579 | if (unlikely(r < 0)) { 2580 | return NULL; 2581 | } else { 2582 | return result; 2583 | } 2584 | } 2585 | } 2586 | static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { 2587 | int is_true = x == Py_True; 2588 | if (is_true | (x == Py_False) | (x == Py_None)) return is_true; 2589 | else return PyObject_IsTrue(x); 2590 | } 2591 | static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { 2592 | #if CYTHON_USE_TYPE_SLOTS 2593 | PyNumberMethods *m; 2594 | #endif 2595 | const char *name = NULL; 2596 | PyObject *res = NULL; 2597 | #if PY_MAJOR_VERSION < 3 2598 | if (PyInt_Check(x) || PyLong_Check(x)) 2599 | #else 2600 | if (PyLong_Check(x)) 2601 | #endif 2602 | return __Pyx_NewRef(x); 2603 | #if CYTHON_USE_TYPE_SLOTS 2604 | m = Py_TYPE(x)->tp_as_number; 2605 | #if PY_MAJOR_VERSION < 3 2606 | if (m && m->nb_int) { 2607 | name = "int"; 2608 | res = PyNumber_Int(x); 2609 | } 2610 | else if (m && m->nb_long) { 2611 | name = "long"; 2612 | res = PyNumber_Long(x); 2613 | } 2614 | #else 2615 | if (m && m->nb_int) { 2616 | name = "int"; 2617 | res = PyNumber_Long(x); 2618 | } 2619 | #endif 2620 | #else 2621 | res = PyNumber_Int(x); 2622 | #endif 2623 | if (res) { 2624 | #if PY_MAJOR_VERSION < 3 2625 | if (!PyInt_Check(res) && !PyLong_Check(res)) { 2626 | #else 2627 | if (!PyLong_Check(res)) { 2628 | #endif 2629 | PyErr_Format(PyExc_TypeError, 2630 | "__%.4s__ returned non-%.4s (type %.200s)", 2631 | name, name, Py_TYPE(res)->tp_name); 2632 | Py_DECREF(res); 2633 | return NULL; 2634 | } 2635 | } 2636 | else if (!PyErr_Occurred()) { 2637 | PyErr_SetString(PyExc_TypeError, 2638 | "an integer is required"); 2639 | } 2640 | return res; 2641 | } 2642 | static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { 2643 | Py_ssize_t ival; 2644 | PyObject *x; 2645 | #if PY_MAJOR_VERSION < 3 2646 | if (likely(PyInt_CheckExact(b))) { 2647 | if (sizeof(Py_ssize_t) >= sizeof(long)) 2648 | return PyInt_AS_LONG(b); 2649 | else 2650 | return PyInt_AsSsize_t(x); 2651 | } 2652 | #endif 2653 | if (likely(PyLong_CheckExact(b))) { 2654 | #if CYTHON_USE_PYLONG_INTERNALS 2655 | const digit* digits = ((PyLongObject*)b)->ob_digit; 2656 | const Py_ssize_t size = Py_SIZE(b); 2657 | if (likely(__Pyx_sst_abs(size) <= 1)) { 2658 | ival = likely(size) ? digits[0] : 0; 2659 | if (size == -1) ival = -ival; 2660 | return ival; 2661 | } else { 2662 | switch (size) { 2663 | case 2: 2664 | if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { 2665 | return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2666 | } 2667 | break; 2668 | case -2: 2669 | if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { 2670 | return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2671 | } 2672 | break; 2673 | case 3: 2674 | if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { 2675 | return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2676 | } 2677 | break; 2678 | case -3: 2679 | if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { 2680 | return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2681 | } 2682 | break; 2683 | case 4: 2684 | if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 2685 | return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2686 | } 2687 | break; 2688 | case -4: 2689 | if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { 2690 | return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); 2691 | } 2692 | break; 2693 | } 2694 | } 2695 | #endif 2696 | return PyLong_AsSsize_t(b); 2697 | } 2698 | x = PyNumber_Index(b); 2699 | if (!x) return -1; 2700 | ival = PyInt_AsSsize_t(x); 2701 | Py_DECREF(x); 2702 | return ival; 2703 | } 2704 | static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { 2705 | return PyInt_FromSize_t(ival); 2706 | } 2707 | 2708 | 2709 | #endif /* Py_PYTHON_H */ 2710 | -------------------------------------------------------------------------------- /KalmanFilterC/CythonExample.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "cpp_test.h": 2 | cdef cppclass Test: 3 | Test() 4 | Test(int test1) 5 | int test1 6 | int returnFive() 7 | Test add "operator+"(Test other) 8 | Test sub "operator-"(Test other) 9 | 10 | cdef class pyTest: 11 | cdef Test* thisptr # hold a C++ instance 12 | def __cinit__(self, int test1): 13 | self.thisptr = new Test(test1) 14 | def __dealloc__(self): 15 | del self.thisptr 16 | 17 | def __add__(pyTest left, pyTest other): 18 | cdef Test t = left.thisptr.add(other.thisptr[0]) 19 | cdef pyTest tt = pyTest(t.test1) 20 | return tt 21 | def __sub__(pyTest left, pyTest other): 22 | cdef Test t = left.thisptr.sub(other.thisptr[0]) 23 | cdef pyTest tt = pyTest(t.test1) 24 | return tt 25 | 26 | def __repr__(self): 27 | return "pyTest[%s]" % (self.thisptr.test1) 28 | 29 | def returnFive(self): 30 | return self.thisptr.returnFive() 31 | 32 | def printMe(self): 33 | return "hello world" 34 | -------------------------------------------------------------------------------- /KalmanFilterC/KalmanFilter.pyx: -------------------------------------------------------------------------------- 1 | #from libc.stdlib cimport malloc, free 2 | import cython 3 | import numpy as np 4 | cimport numpy as np 5 | 6 | cdef extern from "KalmanFilterC.cpp": 7 | double SumArray(double* Array, int length) 8 | cdef cppclass KalmanFilter: 9 | KalmanFilter(int Dimensionality, double* AMatrixFlattened, double* PMatrixFlattened, double* QMatrixFlattened, double* HVector, double* X_InitVector, double RValue) 10 | void FilterData(double* Data, int Length, double* FilteredData) 11 | 12 | cdef class CKalmanFilter: 13 | cdef KalmanFilter* thisptr # hold a C++ instance 14 | 15 | def __cinit__(self, int Dimensionality, np.ndarray[double, ndim=2, mode="c"] AMatrix not None, np.ndarray[double, ndim=2, mode="c"] PMatrix not None, np.ndarray[double, ndim=2, mode="c"] QMatrix not None, np.ndarray[double, ndim=1, mode="c"] HVector not None, np.ndarray[double, ndim=1, mode="c"] X_InitVector not None, double RValue): 16 | cdef double[::1] AMatrixCFlattened = AMatrix.flatten() 17 | cdef double[::1] PMatrixCFlattened = PMatrix.flatten() 18 | cdef double[::1] QMatrixCFlattened = QMatrix.flatten() 19 | cdef double[::1] HVectorC = HVector 20 | cdef double[::1] X_InitVectorC = X_InitVector 21 | self.thisptr = new KalmanFilter(Dimensionality, &AMatrixCFlattened[0], &PMatrixCFlattened[0], &QMatrixCFlattened[0], &HVectorC[0], &X_InitVectorC[0], RValue) 22 | 23 | def __dealloc__(self): 24 | del self.thisptr 25 | 26 | def FilterData(self, np.ndarray[double, ndim=1, mode="c"] Data not None, int Length): 27 | cdef double[::1] DataC = Data 28 | cdef double[::1] FilteredDataResult = np.zeros(Length) 29 | self.thisptr.FilterData(&DataC[0], Length, &FilteredDataResult[0]) 30 | return np.asarray(FilteredDataResult) 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /KalmanFilterC/KalmanFilterC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "MatrixFunctions.h" 5 | 6 | class KalmanFilter{ 7 | public: 8 | KalmanFilter(int Dimensionality, double* AMatrixFlattened, double* PMatrixFlattened, double* QMatrixFlattened, double* HVector, double* X_InitVector, double RValue); // prototype of constructor 9 | ~KalmanFilter(void); // prototype of destructor 10 | void FilterData(double* Data, int Length, double* FilteredData); 11 | std::vector< std::vector > A; // initialise empty 2D (0x0) vector 12 | std::vector< std::vector > P; // initialise empty 2D (0x0) vector 13 | std::vector< std::vector > Q; // initialise empty 2D (0x0) vector 14 | std::vector H; // initialise empty 1D (0 length) vector 15 | std::vector X_Init; // initialise empty 1D (0 length) vector 16 | double R; 17 | private: 18 | int Dimensionality; 19 | }; 20 | 21 | KalmanFilter::KalmanFilter(int DIM, double* AMatrixFlattened, double* PMatrixFlattened, double* QMatrixFlattened, double* HVector, double* X_InitVector, double RValue) 22 | { 23 | Dimensionality = DIM; 24 | 25 | A.resize(Dimensionality, std::vector(Dimensionality)); // resize 2D vector to be (Dim x Dim) 26 | for (int i = 0; i < Dimensionality; ++i) { 27 | for (int j = 0; j < Dimensionality; ++j) { 28 | A[i][j] = AMatrixFlattened[3*i+j]; 29 | } 30 | } 31 | P.resize(Dimensionality, std::vector(Dimensionality)); // resize 2D vector to be (Dim x Dim) 32 | for (int i = 0; i < Dimensionality; ++i) { 33 | for (int j = 0; j < Dimensionality; ++j) { 34 | P[i][j] = PMatrixFlattened[3*i+j]; 35 | } 36 | } 37 | Q.resize(Dimensionality, std::vector(Dimensionality)); // resize 2D vector to be (Dim x Dim) 38 | for (int i = 0; i < Dimensionality; ++i) { 39 | for (int j = 0; j < Dimensionality; ++j) { 40 | Q[i][j] = QMatrixFlattened[3*i+j]; 41 | } 42 | } 43 | H.resize(Dimensionality); 44 | for (int i = 0; i < Dimensionality; ++i) { 45 | H[i] = HVector[i]; 46 | } 47 | X_Init.resize(Dimensionality); 48 | for (int i = 0; i < Dimensionality; ++i) { 49 | X_Init[i] = X_InitVector[i]; 50 | } 51 | 52 | R = RValue; 53 | }; 54 | 55 | KalmanFilter::~KalmanFilter(void){ 56 | std::cout << "Being Destroyed!" << "\n"; 57 | }; 58 | 59 | void KalmanFilter::FilterData(double* Data, int Length, double* FilteredData){ 60 | std::vector CurrentStateVector; 61 | CurrentStateVector.resize(Dimensionality); 62 | std::vector PredictedStateVector; 63 | PredictedStateVector.resize(Dimensionality); 64 | std::vector< std::vector > CurrentProcessCovarianceMatrix; 65 | CurrentProcessCovarianceMatrix.resize(Dimensionality, std::vector(Dimensionality)); 66 | std::vector< std::vector > PredictedProcessCovarianceMatrix_temp1; 67 | PredictedProcessCovarianceMatrix_temp1.resize(Dimensionality, std::vector(Dimensionality)); 68 | std::vector< std::vector > PredictedProcessCovarianceMatrix; 69 | PredictedProcessCovarianceMatrix.resize(Dimensionality, std::vector(Dimensionality)); 70 | std::vector< std::vector > ATimesP; 71 | ATimesP.resize(Dimensionality, std::vector(Dimensionality)); 72 | std::vector< std::vector > A_Transpose; 73 | A_Transpose.resize(Dimensionality, std::vector(Dimensionality)); 74 | double MeasurementPredicionResidual, HtimesXpk, KalmanGain_Denominator; 75 | std::vector KalmanGain_Denominator_temp1; 76 | KalmanGain_Denominator_temp1.resize(Dimensionality); 77 | std::vector H_T; 78 | H_T.resize(Dimensionality); 79 | std::vector KalmanGain_Numerator; 80 | KalmanGain_Numerator.resize(Dimensionality); 81 | std::vector KalmanGain; 82 | KalmanGain.resize(Dimensionality); 83 | std::vector CurrentStateVector_temp1; 84 | CurrentStateVector_temp1.resize(Dimensionality); 85 | std::vector< std::vector > KalmanGainTimesH; 86 | KalmanGainTimesH.resize(Dimensionality, std::vector(Dimensionality)); 87 | std::vector< std::vector > CurrentProcessCovarianceMatrix_temp1; 88 | CurrentProcessCovarianceMatrix_temp1.resize(Dimensionality, std::vector(Dimensionality)); 89 | std::vector< std::vector > identityMatrix; 90 | identityMatrix.resize(Dimensionality, std::vector(Dimensionality, 0.0)); // init to all zeros 91 | 92 | for (int i=0; i 2 | 3 | void printMatrix(std::vector< std::vector > matrix){ 4 | int i, j; 5 | int N = matrix.size(); 6 | for(i=0; i vector){ 16 | int i; 17 | int N = vector.size(); 18 | for(i=0; i >& Matrix, std::vector& Vector, std::vector* Result){ 26 | int i, j; 27 | int N = (*Result).size(); 28 | for(j=0; j >& Matrix1, std::vector< std::vector >& Matrix2, std::vector< std::vector >* Result){ 41 | int i, j, k; 42 | int N = (*Result).size(); 43 | for(i=0; i >& Matrix, std::vector< std::vector >* Result){ 59 | int i, j; 60 | int N = (*Result).size(); 61 | for(i=0; i >& Matrix1, std::vector< std::vector >& Matrix2, std::vector< std::vector >* Result){ 70 | int i, j; 71 | int N = (*Result).size(); 72 | for(i=0; i >& Matrix1, std::vector< std::vector >& Matrix2, std::vector< std::vector >* Result){ 80 | int i, j; 81 | int N = (*Result).size(); 82 | for(i=0; i& RowVector, std::vector< std::vector >& Matrix, std::vector* Result){ 98 | int i, k; 99 | int N = (*Result).size(); 100 | for(i=0; i& RowVector, std::vector& ColVector){ 113 | int i; 114 | double Result = 0; 115 | int N = RowVector.size(); 116 | for(i=0; i& Vector, double Number, std::vector* Result){ 124 | int i; 125 | int N = (*Result).size(); 126 | for(i=0; i& Vector, double Number, std::vector* Result){ 132 | int i; 133 | int N = (*Result).size(); 134 | for(i=0; i& Vector1, std::vector& Vector2, std::vector* Result){ 140 | int i; 141 | int N = (*Result).size(); 142 | for(i=0; i& ColVector, std::vector& RowVector, std::vector< std::vector >* Result){ 148 | int i, j; 149 | int N = (*Result).size(); 150 | for(i=0; i8 random numbers and runs each version of the sum function of this array. It prints out the time taken for each function to sum the array (recorded by a function wrapper) and the value calculated by each function. 10 | 11 | | Implementation | elapsed time (s) | 12 | |-----------------------|------------------| 13 | | Python sum() | 7.326408 | 14 | | numpy np.sum() | 0.038284 | 15 | | C++ sum | 0.108173 | 16 | | C++ sum with OpenMP | 0.042143 | 17 | 18 | In ClassCythonCPP I have implemented a simple class in C++ and wrapped it in cython such that you may create an instance in python of this class. 19 | 20 | In ClassCythoncppWithMemberFunctions I have extended this simple class to take a numpy array in the constructor and convert it to a C array stored in the object. I have then added a member function to the class which sums the elements in this list and returns a double containing this sum total. The returned number may be accessed from Python. 21 | 22 | -------------------------------------------------------------------------------- /SumNumpyArray/SumArray/SumArray.pyx: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | import numpy as np 4 | cimport numpy as np 5 | 6 | cdef extern from "SumArrayC.cpp": 7 | double SumArray(double* Array, int length) 8 | 9 | @cython.boundscheck(False) 10 | @cython.wraparound(False) 11 | def C_SumArray(np.ndarray[double, mode="c"] InputArray not None, int length): 12 | return SumArray(&InputArray[0], length) 13 | -------------------------------------------------------------------------------- /SumNumpyArray/SumArray/SumArrayC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | double SumArray(double* Array, int length){ 4 | double Sum = 0.0; 5 | 6 | for(int i=0; i 2 | 3 | double SumArray(double* Array, int length){ 4 | double Sum = 0.0; 5 | 6 | #pragma omp parallel for reduction (+:Sum) 7 | for(int i=0; i