forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 3
/
reshape_helper.pxi.in
81 lines (64 loc) · 1.96 KB
/
reshape_helper.pxi.in
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Template for each `dtype` helper function for take
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
"""
# ----------------------------------------------------------------------
# reshape
# ----------------------------------------------------------------------
{{py:
# name, c_type
dtypes = [('uint8', 'uint8_t'),
('uint16', 'uint16_t'),
('uint32', 'uint32_t'),
('uint64', 'uint64_t'),
('int8', 'int8_t'),
('int16', 'int16_t'),
('int32', 'int32_t'),
('int64', 'int64_t'),
('float32', 'float32_t'),
('float64', 'float64_t'),
('object', 'object')]
}}
{{for dtype, c_type in dtypes}}
@cython.wraparound(False)
@cython.boundscheck(False)
def unstack_{{dtype}}(ndarray[{{c_type}}, ndim=2] values,
ndarray[uint8_t, ndim=1] mask,
Py_ssize_t stride,
Py_ssize_t length,
Py_ssize_t width,
ndarray[{{c_type}}, ndim=2] new_values,
ndarray[uint8_t, ndim=2] new_mask):
"""
transform long sorted_values to wide new_values
Parameters
----------
values : typed ndarray
mask : boolean ndarray
stride : int
length : int
width : int
new_values : typed ndarray
result array
new_mask : boolean ndarray
result mask
"""
cdef:
Py_ssize_t i, j, w, nulls, s, offset
{{if dtype == 'object'}}
if True:
{{else}}
with nogil:
{{endif}}
for i in range(stride):
nulls = 0
for j in range(length):
for w in range(width):
offset = j * width + w
if mask[offset]:
s = i * width + w
new_values[j, s] = values[offset - nulls, i]
new_mask[j, s] = 1
else:
nulls += 1
{{endfor}}