56
56
take_1d_template = """@cython.wraparound(False)
57
57
def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s] values,
58
58
ndarray[int64_t] indexer,
59
- out, fill_value=np.nan):
59
+ ndarray[%(c_type_out)s] out,
60
+ fill_value=np.nan):
60
61
cdef:
61
62
Py_ssize_t i, n, idx
62
- ndarray[%(c_type_out)s] outbuf = out
63
63
%(c_type_out)s fv
64
64
65
65
n = len(indexer)
@@ -68,20 +68,20 @@ def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s] values,
68
68
for i from 0 <= i < n:
69
69
idx = indexer[i]
70
70
if idx == -1:
71
- outbuf [i] = fv
71
+ out [i] = fv
72
72
else:
73
- outbuf [i] = %(preval)svalues[idx]%(postval)s
73
+ out [i] = %(preval)svalues[idx]%(postval)s
74
74
75
75
"""
76
76
77
77
take_2d_axis0_template = """@cython.wraparound(False)
78
78
@cython.boundscheck(False)
79
79
def take_2d_axis0_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
80
80
ndarray[int64_t] indexer,
81
- out, fill_value=np.nan):
81
+ ndarray[%(c_type_out)s, ndim=2] out,
82
+ fill_value=np.nan):
82
83
cdef:
83
84
Py_ssize_t i, j, k, n, idx
84
- ndarray[%(c_type_out)s, ndim=2] outbuf = out
85
85
%(c_type_out)s fv
86
86
87
87
n = len(indexer)
@@ -98,37 +98,40 @@ def take_2d_axis0_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
98
98
idx = indexer[i]
99
99
if idx == -1:
100
100
for j from 0 <= j < k:
101
- outbuf [i, j] = fv
101
+ out [i, j] = fv
102
102
else:
103
103
v = &values[idx, 0]
104
- o = &outbuf [i, 0]
104
+ o = &out [i, 0]
105
105
memmove(o, v, <size_t>(sizeof(%(c_type_out)s) * k))
106
106
return
107
107
108
108
for i from 0 <= i < n:
109
109
idx = indexer[i]
110
110
if idx == -1:
111
111
for j from 0 <= j < k:
112
- outbuf [i, j] = fv
112
+ out [i, j] = fv
113
113
else:
114
114
for j from 0 <= j < k:
115
- outbuf [i, j] = %(preval)svalues[idx, j]%(postval)s
115
+ out [i, j] = %(preval)svalues[idx, j]%(postval)s
116
116
117
117
"""
118
118
119
119
take_2d_axis1_template = """@cython.wraparound(False)
120
120
@cython.boundscheck(False)
121
121
def take_2d_axis1_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
122
122
ndarray[int64_t] indexer,
123
- out, fill_value=np.nan):
123
+ ndarray[%(c_type_out)s, ndim=2] out,
124
+ fill_value=np.nan):
124
125
cdef:
125
126
Py_ssize_t i, j, k, n, idx
126
- ndarray[%(c_type_out)s, ndim=2] outbuf = out
127
127
%(c_type_out)s fv
128
128
129
129
n = len(values)
130
130
k = len(indexer)
131
-
131
+
132
+ if n == 0 or k == 0:
133
+ return
134
+
132
135
fv = fill_value
133
136
134
137
IF %(can_copy)s:
@@ -140,34 +143,34 @@ def take_2d_axis1_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
140
143
idx = indexer[j]
141
144
if idx == -1:
142
145
for i from 0 <= i < n:
143
- outbuf [i, j] = fv
146
+ out [i, j] = fv
144
147
else:
145
148
v = &values[0, idx]
146
- o = &outbuf [0, j]
149
+ o = &out [0, j]
147
150
memmove(o, v, <size_t>(sizeof(%(c_type_out)s) * n))
148
151
return
149
152
150
153
for j from 0 <= j < k:
151
154
idx = indexer[j]
152
155
if idx == -1:
153
156
for i from 0 <= i < n:
154
- outbuf [i, j] = fv
157
+ out [i, j] = fv
155
158
else:
156
159
for i from 0 <= i < n:
157
- outbuf [i, j] = %(preval)svalues[i, idx]%(postval)s
160
+ out [i, j] = %(preval)svalues[i, idx]%(postval)s
158
161
159
162
"""
160
163
161
164
take_2d_multi_template = """@cython.wraparound(False)
162
165
@cython.boundscheck(False)
163
166
def take_2d_multi_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
164
167
indexer,
165
- out, fill_value=np.nan):
168
+ ndarray[%(c_type_out)s, ndim=2] out,
169
+ fill_value=np.nan):
166
170
cdef:
167
171
Py_ssize_t i, j, k, n, idx
168
172
ndarray[int64_t] idx0 = indexer[0]
169
173
ndarray[int64_t] idx1 = indexer[1]
170
- ndarray[%(c_type_out)s, ndim=2] outbuf = out
171
174
%(c_type_out)s fv
172
175
173
176
n = len(idx0)
@@ -178,13 +181,13 @@ def take_2d_multi_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
178
181
idx = idx0[i]
179
182
if idx == -1:
180
183
for j from 0 <= j < k:
181
- outbuf [i, j] = fv
184
+ out [i, j] = fv
182
185
else:
183
186
for j from 0 <= j < k:
184
187
if idx1[j] == -1:
185
- outbuf [i, j] = fv
188
+ out [i, j] = fv
186
189
else:
187
- outbuf [i, j] = %(preval)svalues[idx, idx1[j]]%(postval)s
190
+ out [i, j] = %(preval)svalues[idx, idx1[j]]%(postval)s
188
191
189
192
"""
190
193
@@ -2169,7 +2172,7 @@ def generate_put_template(template, use_ints = True, use_floats = True):
2169
2172
2170
2173
output = StringIO ()
2171
2174
for name , c_type , dest_type , dest_dtype in function_list :
2172
- func = template % {'name' : name ,
2175
+ func = template % {'name' : name ,
2173
2176
'c_type' : c_type ,
2174
2177
'dest_type' : dest_type .replace ('_t' , '' ),
2175
2178
'dest_type2' : dest_type ,
@@ -2203,7 +2206,7 @@ def generate_take_template(template, exclude=None):
2203
2206
]
2204
2207
2205
2208
output = StringIO ()
2206
- for (name , dest , c_type_in , c_type_out ,
2209
+ for (name , dest , c_type_in , c_type_out ,
2207
2210
preval , postval , can_copy ) in function_list :
2208
2211
if exclude is not None and name in exclude :
2209
2212
continue
0 commit comments