-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_numbers.py
executable file
·48 lines (38 loc) · 996 Bytes
/
generate_numbers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
numbers = open('arrex/numbers.pyx', 'w')
numbers.write('''# cython: language_level=3, cdivision=True
cimport cython
from cpython cimport PyObject, Py_DECREF
from libc.stdint cimport *
from .dtypes cimport *
cdef DDType decl
''')
template = '''
### declare {ctype}
cdef int pack_{layout}(object dtype, {ctype}* place, object obj) except -1:
place[0] = obj
cdef object unpack_{layout}(object dtype, {ctype}* place):
return place[0]
decl = DDType()
decl.dsize = sizeof({ctype})
decl.c_pack = <c_pack_t> pack_{layout}
decl.c_unpack = <c_unpack_t> unpack_{layout}
decl.layout = b'{layout}'
declare('{layout}', decl)
'''
for layout, ctype in [
('d', 'double'),
('f', 'float'),
('b', 'int8_t'),
('B', 'uint8_t'),
('h', 'int16_t'),
('H', 'uint16_t'),
('i', 'int32_t'),
('I', 'uint32_t'),
('l', 'int64_t'),
('L', 'uint64_t'),
]:
numbers.write(template.format(layout=layout, ctype=ctype))
numbers.write('''
declare(float, declared('d'))
declare(int, declared('l'))
''')