Debian Codegraph @

brian2/codegen/runtime/cython_rt/templates/common_group.pyx

raw
1 {% macro cython_directives() %}
2 #cython: language_level=3
3 #cython: boundscheck=False
4 #cython: wraparound=False
5 #cython: cdivision=False
6 #cython: cpow=True
7 #cython: infer_types=True
8 {% endmacro %}
9
10 {% macro imports() %}
11 import numpy as _numpy
12 cimport numpy as _numpy
13 from libc.math cimport fabs, sin, cos, tan, sinh, cosh, tanh, exp, log, log10, expm1, log1p, sqrt, asin, acos, atan, fmod, floor, ceil, isinf
14 cdef extern from "math.h":
15 double M_PI
16 # Import the two versions of std::abs
17 from libc.stdlib cimport abs # For integers
18 from libc.math cimport abs # For floating point values
19 from libc.limits cimport INT_MIN, INT_MAX
20 from libcpp cimport bool
21 from libcpp.set cimport set
22 from cython.operator cimport dereference as _deref, preincrement as _preinc
23 cimport cython as _cython
24
25 _numpy.import_array()
26 cdef extern from "numpy/ndarraytypes.h":
27 void PyArray_CLEARFLAGS(_numpy.PyArrayObject *arr, int flags)
28 from libc.stdlib cimport free
29
30 cdef extern from "numpy/npy_math.h":
31 bint npy_isinf(double x)
32 double NPY_INFINITY
33
34 cdef extern from "stdint_compat.h":
35 # Longness only used for type promotion
36 # Actual compile time size used for conversion
37 ctypedef signed int int32_t
38 ctypedef signed long int64_t
39 ctypedef unsigned long uint64_t
40 # It seems we cannot used a fused type here
41 cdef int int_(bool)
42 cdef int int_(char)
43 cdef int int_(short)
44 cdef int int_(int)
45 cdef int int_(long)
46 cdef int int_(float)
47 cdef int int_(double)
48 cdef int int_(long double)
49
50 # PyCapsule support for direct C++ pointer access
51 from cpython.pycapsule cimport PyCapsule_GetPointer
52
53 # Dynamic array C++ interface declarations
54 cdef extern from "dynamic_array.h":
55 cdef cppclass DynamicArray1DCpp "DynamicArray1D"[T]:
56 void resize(size_t) except +
57 void shrink_to_fit()
58 T& operator[](size_t)
59 T* get_data_ptr()
60 size_t size()
61 size_t capacity()
62
63 cdef cppclass DynamicArray2DCpp "DynamicArray2D"[T]:
64 void resize(size_t, size_t) except +
65 void resize_along_first(size_t) except +
66 void shrink_to_fit()
67 T& operator()(size_t, size_t)
68 T* get_data_ptr()
69 size_t rows()
70 size_t cols()
71 size_t stride()
72 {% endmacro %}
73
74 {% macro before_run() %}
75 {{ cython_directives() }}
76 {{ imports() }}
77
78 # support code
79 {{ support_code_lines | autoindent }}
80
81 def main(_namespace):
82 {{ load_namespace | autoindent }}
83 if '_owner' in _namespace:
84 _owner = _namespace['_owner']
85 {% block before_code %}
86 # EMPTY_CODE_BLOCK -- overwrite in child template
87 {% endblock %}
88 {% endmacro %}
89
90 {% macro run() %}
91 {{ cython_directives() }}
92 {{ imports() }}
93
94 # support code
95 {{ support_code_lines | autoindent }}
96
97 # template-specific support code
98 {% block template_support_code %}
99 {% endblock %}
100
101 def main(_namespace):
102 cdef size_t _idx
103 cdef size_t _vectorisation_idx
104 {{ load_namespace | autoindent }}
105 if '_owner' in _namespace:
106 _owner = _namespace['_owner']
107 {% block maincode %}
108 {% endblock %}
109
110 {% endmacro %}
111
112 {% macro after_run() %}
113 {{ cython_directives() }}
114 {{ imports() }}
115
116 # support code
117 {{support_code_lines | autoindent}}
118
119 def main(_namespace):
120 {{ load_namespace | autoindent }}
121 if '_owner' in _namespace:
122 _owner = _namespace['_owner']
123 {% block after_code %}
124 # EMPTY_CODE_BLOCK -- overwrite in child template
125 {% endblock %}
126 {% endmacro %}